pycharm提示:无法加载文件 C:\Users\HUAWEI\Desktop\djangoProject\venv\Scripts\activate.ps1,因为在此系统上禁止运行脚本

遇到这个问题:

无法加载文件 C:\Users\HUAWEI\Desktop\djangoProject\venv\Scripts\activate.ps1,因为在此系统上禁止运行脚本。有关osoft.co
m/fwlink/?LinkID=135170 中的 about_Execution_Policies。

  • CategoryInfo : SecurityError: ( : ) [],ParentContainsErrorRecordException
  • FullyQualifiedErrorId : UnauthorizedAccess

原文出自这里

原因

r e s t r i c t e d restricted restricted(防止运行没有数字签名的脚本),要设置成 r e m o t e s i g n e d remotesigned remotesigned模式。

解决方法

先在 p y c h a r m pycharm pycharm终端输入 g e t − e x e c u t i o n p o l i c y get-executionpolicy getexecutionpolicy可以查看到有没有这个权限。

PS XXXXXXXXX> get-executionpolicy
Restricted
PS XXXXX>

然后以管理员的方式打开 P o w e r s h a l Powershal Powershall运行,并在命令窗口输入 s e t − e x e c u t i o n p o l i c y   r e m o t e s i g n e d set-executionpolicy\ remotesigned setexecutionpolicy remotesigned更改执行策略,然后输入 Y Y Y

PS C:\WINDOWS\system32> Set-ExecutionPolicy RemoteSigned

执行策略更改
执行策略可帮助你防止执行不信任的脚本。更改执行策略可能会产生安全风险,如 https:/go.microsoft.com/fwlink/?LinkID=135170
中的 about_Execution_Policies 帮助主题所述。是否要更改执行策略?
[Y](Y)  [A] 全是(A)  [N](N)  [L] 全否(L)  [S] 暂停(S)  [?] 帮助 (默认值为“N”): Y
PS C:\WINDOWS\system32>

最后再 p y c h a r m pycharm pycharm终端继续输入 g e t − e x e c u t i o n p o l i c y get-executionpolicy getexecutionpolicy验证。

PS XXXXXXXXX> get-executionpolicy
RemoteSigned
PS XXXXX>

出现 R e m o t e S i g n e d RemoteSigned RemoteSigned 这个字符就代表更改成功。

猜你喜欢

转载自blog.csdn.net/weixin_45652283/article/details/131608532