virtualenv 激活不起作用

wan*_*810 5 python powershell virtualenv

我正在尝试创建一个虚拟环境来测试 api。

我可以使用 很好地创建环境virtualenv test,然后我可以 cd 进入它。当我尝试运行时activate,出现此错误:

PS C:\Users\Bright Bridge\Desktop\autocomplete_demo\Scripts> activate
activate : The term 'activate' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if
a path was included, verify that the path is correct and try again.
At line:1 char:1
+ activate
+ ~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (activate:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException


Suggestion [3,General]: The command activate was not found, but does exist in the current location. Windows PowerShell does not load commands from the current
 location by default. If you trust this command, instead type: ".\activate". See "get-help about_Command_Precedence" for more details.
Run Code Online (Sandbox Code Playgroud)

我最近更新了 Windows,它用 Windows Powershell 替换了 cmd。我的 virtualenv 与 cmd 一起工作得很好,所以我怀疑它可能与 Powershell 做事的方式有关。

如何激活 virtualenv?

Bug*_*eeb 11

对于那些仍然感兴趣的人,输出给出了答案:

如果您信任此命令,请键入:“.\activate”。

因此在powershell中使用相对路径名运行activate脚本,或者使用绝对路径


Rah*_*han 7

您需要设置 Windows 执行策略。根据virtualenv的官方文档。

在 powershell 中运行Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUse

现在您可以激活虚拟环境。使用\Scripts\Activate.ps1

希望它能解决它!


Aet*_*und 6

如果您按WindowsKey + R,并cmd在该框出现时键入,它应该会显示命令行界面而不是 powershell!


小智 6

只需输入一个 PowerShell 命令

  1. .\脚本\激活

    而不是

  2. ./脚本/激活