我有一个名为 env 的虚拟环境和一个名为 project_2 的项目。 我想在 VScode 中激活环境,但我不能(我可以在命令提示符中激活它)。
当我想在 VScode 中激活虚拟环境时,它会显示此文本
PS C:\Users\User1\Documents\programming\python\django> project_2\scripts\activate.ps1
project_2\scripts\activate.ps1 : File
C:\Users\User1\Documents\programming\python\django\project_2\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
+ project_2\scripts\activate.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
我现在应该做什么?
例如,您可以打开错误消息为您提供的链接。
您会发现它是与安全相关的东西,可以保护您的电脑和您自己免受不需要的和未经授权的脚本在您的计算机上自由运行的影响。
默认设置将避免运行未签名(或根本没有,我不记得)的脚本。
要覆盖该行为,您可以按照官方文档的说明运行这些 Powershell 命令以降低保护并允许脚本执行。