Windows系统PyCharm中的terminal打不开虚拟环境问题

报以下错误:

无法加载文件 C:\fzq\project\autotest\venv\Scripts\activate.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。 + CategoryInfo : SecurityError: (:) [],ParentContainsErrorRecordException + FullyQualifiedErrorId : UnauthorizedAccess

解决方法:

  1. 以管理员身份打开PowerShell:

    • 在Windows搜索栏输入PowerShell

    • 右键选择 "以管理员身份运行"

  2. 更改执行策略:

    powershell
     
    Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
    • 输入 Y 确认更改

    • 此命令允许运行本地创建的脚本(如虚拟环境脚本)

  3. 在PyCharm中重试:

    • 关闭并重新打开PyCharm的Terminal

    • 再次运行 .\venv\Scripts\activate.ps1

posted on 2025-08-19 11:11  fengZQ  阅读(44)  评论(0)    收藏  举报

导航