2

当我尝试使用命令激活虚拟环境workon <name>时,虚拟环境没有激活。我使用的是 Windows 10 机器并安装了 Virtualenv、VirtualenvWrapper 和 VirtualenvWrapper-win。

例如,当我输入lsvirtualenv命令 shell 时,我可以看到<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-ExecutionPolicycmdlet 来识别:

PS C:\Users\Administrator> get-executionpolicy

为了更改现行执行策略,Set-ExecutionPolicy cmdlet 与新的执行策略设置结合使用。例如,要更改为 RemoteSigned,应执行以下命令:

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

执行策略 描述 受限 Windows PowerShell 上的默认策略,此模式禁用脚本文件的执行。Windows PowerShell 只能通过在命令提示符下手动发出命令来使用。

AllSigned 将执行限制为验证码签名的脚本。执行签名脚本时,PowerShell 将提示确认脚本的签名者是否可信。

RemoteSigned 要求从远程位置下载的任何脚本必须先签名,然后才能被允许执行。

Unrestricted 允许执行任何脚本,无论其来源或是否已签名。

4

1 回答 1

0

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

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

PS C:\> Set-ExecutionPolicy RemoteSigned
于 2016-08-31T07:58:16.150 回答