无法加载,因为在此系统上禁用了正在运行的脚本。有关更多信息,请参阅 about_Execution_Policies,网址为

Ahm*_*del 3 python visual-studio-code

它工作正常,然后出现错误。解决它后我总是得到这个错误,无论项目是什么

输出:

& : File C:\Users\pc\Documents\python\venv\Scripts\Activate.ps1 cannot be loaded because running scripts is 
    disabled on this system. For more information, see about_Execution_Policies at 
    https:/go.microsoft.com/fwlink/?LinkID=135170.
    At line:1 char:3
    + & c:/Users/pc/Documents/python/venv/Scripts/Activate.ps1
    +   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : SecurityError: (:) [], PSSecurityException       
        + FullyQualifiedErrorId : UnauthorizedAccessenter code here
Run Code Online (Sandbox Code Playgroud)

Cod*_*ker 26

如果您遇到这样的错误,

在此输入图像描述

我们可以使用以下步骤解决该问题,

  • ExecutionPolicy通过以下命令获取电流状态:

    Get-ExecutionPolicy
    
    Run Code Online (Sandbox Code Playgroud)

    默认情况下它是受限制的。为了允许执行 PowerShell 脚本,我们需要将此 ExecutionPolicy 设置为 Unrestricted 或 Bypass。

  • Bypass我们可以使用以下任何 PowerShell 命令来设置当前用户的策略:

    Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted -Force
    Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force
    
    Run Code Online (Sandbox Code Playgroud)

    无限制策略加载所有配置文件并运行所有脚本。如果您运行从 Internet 下载的未签名脚本,系统会在运行前提示您授予权限。

    而在绕过策略中,不会阻止任何内容,并且在脚本执行期间不会出现警告或提示。绕过ExecutionPolicy比 轻松多了Unrestricted


L. *_*der 22

可能还想考虑将其设置为:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Run Code Online (Sandbox Code Playgroud)

您将收到一条有关执行策略更改的消息(显然),我对此说“A”表示全部同意。选择最适合您的。

这应该允许您运行自己的脚本,但任何来自其他地方的脚本都需要批准。

*为清楚起见,对以上帖子进行了编辑


San*_*gia 11

只需在 powershell 中输入此内容即可

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted 
Run Code Online (Sandbox Code Playgroud)

并且它将被启用


mcd*_*291 8

这是因为您运行脚本的用户未定义ExecutionPolicy您可以通过在 powershell 中运行以下命令来解决此问题:Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

  • 使用这种方法安全吗? (9认同)
  • 这对我不起作用,“Get-ExecutionPolicy”返回“Unrestricted”,但错误仍然相同。 (2认同)
  • @enthu 请参阅下面 /sf/answers/4942018581/ 的答案:“Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser” (2认同)

小智 5

只需以管理员身份打开 Windows Powershell 并执行此命令即可Set-ExecutionPolicy Unrestricted -Force。问题将得到解决,您可以在 VS code 或 CMD 中激活它。