Virtualenvwrapperwin已安装在Windows 10上,但无法激活虚拟环境

2024-06-10 02:19:46 发布

您现在位置:Python中文网/ 问答频道 /正文

当我尝试使用命令workon <name>激活虚拟环境时,虚拟环境不会激活。我使用的是Windows10机器,安装了Virtualenv、VirtualEnvRapper和VirtualEnvRapper win。在

例如,当我在命令shell中输入lsvirtualenv时,我可以看到<name>虚拟环境存在,但我无法激活它。你能帮帮我吗?在

编辑1:

当我试图直接激活文件时,我从终端收到以下错误:

PS C:\users\stefan\envs\rango\scripts> .\activate .\activate : File C:\users\stefan\envs\rango\scripts\activate.ps1 cannot be loaded. The contents of file C:\users\stefan\envs\rango\scripts\activate.ps1 might have been changed by an unauthorized user or process, because the hash of the file does not match the hash stored in the digital signature. The script cannot run on the specified system. For more information, run Get-Help about_Signing.. At line:1 char:1 + .\activate + ~~~~~~~~~~ + CategoryInfo : SecurityError: (:) [], PSSecurityException + FullyQualifiedErrorId : Unauth – 

编辑2-

我以管理员身份运行powershell并将执行策略更改为“remotesigned”,从而使其正常工作。方法如下:

如果当前控制台未提升并且您尝试执行的操作 需要提升的权限,然后可以使用“Run as administrator”启动powershell 选项:

^{pr2}$

可以使用Get-ExecutionPolicycmdlet标识当前执行策略:

PS C:\Users\Administrator> get-executionpolicy

为了更改当前的执行策略,Set-ExecutionPolicy cmdlet是 与新的执行策略设置结合使用。例如,更改为 远程签名时,应执行以下命令:

PS C:\Users\Administrator> set-executionpolicy remotesigned

Execution Policy Description Restricted The default policy on Windows PowerShell, this mode disables the execution of script files. Windows PowerShell may only be used by manually issuing commands at the command prompt.

AllSigned Limits execution to scripts which are authenticode signed. When a signed script is executed, PowerShell will prompt for confirmation that the signer of the script can be trusted.

RemoteSigned Requires that any scripts that have been downloaded from a remote location must be signed before they may are permitted to execute.

Unrestricted Allows any script to be executed, regardless of origin or whether it is signed.


Tags: ofthe命令虚拟环境scriptsscriptbe策略
1条回答
网友
1楼 · 发布于 2024-06-10 02:19:46

根据virtualenv docs,一个可能的解决方案是放宽系统执行策略,允许在不验证代码签名的情况下运行本地脚本。在

为此,请以管理员身份运行powershell,cd到您的C:>;目录,然后键入以下命令:

PS C:\> Set-ExecutionPolicy RemoteSigned

相关问题 更多 >