当我尝试使用命令激活虚拟环境时workon <name>
,虚拟环境不会激活。我正在使用Windows 10计算机并安装了Virtualenv,VirtualenvWrapper和VirtualenvWrapper-win。
例如,当我输入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 :
PS> Start-Process powershell -Verb runAs
可以使用Get-ExecutionPolicy
cmdlet标识当前执行策略:
PS C:\Users\Administrator> get-executionpolicy
为了更改主要的执行策略,Set-ExecutionPolicy cmdlet与新的执行策略设置一起使用。例如,要更改为RemoteSigned,应执行以下命令:
PS C:\Users\Administrator> set-executionpolicy remotesigned
执行策略说明受限Windows PowerShell上的默认策略,此模式禁用脚本文件的执行。Windows PowerShell只能通过在命令提示符下手动发出命令来使用。
AllSigned将执行限制为经过Authenticode签名的脚本。执行签名脚本后,PowerShell会提示您确认脚本的签名者可以信任。
RemoteSigned要求所有从远程位置下载的脚本都必须先签名,然后才能允许它们执行。
Unrestricted允许执行任何脚本,无论其来源或是否已签名。
从virtualenv文档中,一种可能的解决方案是放宽系统执行策略,以允许在不验证代码签名的情况下运行本地脚本。
为此,请以管理员身份运行powershell,cd到C:>目录,然后键入以下命令:
PS C:\> Set-ExecutionPolicy RemoteSigned
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句