虚拟环境不会在Windows 10上激活

时间:2020-02-12 19:16:06

标签: python powershell cmd windows-10 virtualenv

我使用Windows 10,python 3.7.4,并且已通过pip安装virtualenv。 当我尝试在cmd中创建虚拟环境时,可以使用virtualenv myenv.创建虚拟环境,它会创建所需的文件,Scripts文件夹和激活文件。但是当我尝试激活时什么也没发生。我尝试:

C:\Users\Spike\pyenv>cd crawler

C:\Users\Spike\pyenv\crawler>cd scripts

C:\Users\Spike\pyenv\crawler\Scripts>activate

此虚拟环境名称后的括号应如下所示:

(crawler) C:\Users\Spike\pyenv\crawler\Scripts

但是没有,虚拟环境没有被激活,它像这样继续:

C:\Users\Spike\pyenv\crawler\Scripts>

我已尝试在管理员模式下运行cmd,但无法正常工作。

我尝试从Powershell激活:

PS C:\Users\Spike\pyenv\crawler> cd scripts
PS C:\Users\Spike\pyenv\crawler\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

因此,我在Powershell上尝试了Set-ExecutionPolicy AllSigned和Set-ExecutionPolicy Unrestricted -Force在Powershell上对其进行强制激活之前,它也不起作用。

我也试图在cmder中激活它,我得到的结果与在cmd中得到的结果相同。

要解决这个问题,我首先查看了其他stackoverflow线程,但没有帮助。

1 个答案:

答案 0 :(得分:0)

检查您的virtualenv的名称。您说您的环境名称是myenv。但是,您位于pyenv目录中。如果将CD刻录到创建myenv时所在的文件夹,则应该可以进行以下操作。

myenv/Sripts/activate

如果这不起作用,请确保激活文件确实在其中。

此外,请注意,在某些情况下,virtualenv会启动,但您不会获得(myenv)行为。运行以下命令以查看virtualenv是否已激活。

which python