代码之家  ›  专栏  ›  技术社区  ›  Himanshu Poddar

VS代码终端:无法加载Activate.ps1,因为此系统上已禁用运行脚本

  •  0
  • Himanshu Poddar  · 技术社区  · 4 年前

    我用python创建了一个虚拟环境,现在在vscode中从命令行激活它时,我遇到了错误

    PS C:\Users\hpoddar\Desktop\WebDev\ReactComplete\DjangoReact\ArticlesApp\APIProject> ..\venv\scripts\activate    
    ..\venv\scripts\activate : File C:\Users\hpoddar\Desktop\WebDev\ReactComplete\DjangoReact\ArticlesApp\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:1
    + ..\venv\scripts\activate
    + ~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : SecurityError: (:) [], PSSecurityException
        + FullyQualifiedErrorId : UnauthorizedAccess
    

    这是我的项目结构

    enter image description here

    但是,如果我从命令行激活它,它就会正常工作而不会出现任何错误。

    Python版本:3.9.2

    enter image description here

    2 回复  |  直到 4 年前
        1
  •  63
  •   pxDav    4 年前

    一种方法是将VSCode中的终端更改为命令提示符而不是PowerShell。

    1. 打开终端右侧的下拉菜单并选择 Select Default Profile 1

    2. 从选项中选择“命令提示符”。 enter image description here

    或者,您也可以将执行策略设置为 RemoteSigned Unrestricted 在PowerShell中

    注意:这只影响当前用户

    1. 打开PowerShell

    2. 运行以下命令: Set-ExecutionPolicy RemoteSigned -Scope CurrentUser Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser

    (删除 -Scope CurrentUser 适用于所有用户)