我创建了一个virtualenv围绕我的项目,但当我尝试激活它时,我不能。 这可能只是语法或文件夹位置的问题,但我现在被难住了。

您可以在下面看到,我创建了virtualenv并将其命名为venv。一切看起来都很好,然后我尝试通过运行source venv/bin/activate来激活它

我想这可能只是与我的系统路径有关,但不确定指向什么(我确实知道如何编辑路径)。我使用的是python 7 / windows操作系统,虚拟环境2.2.x

Processing dependencies for virtualenv
Finished processing dependencies for virtualenv

c:\testdjangoproj\mysite>virtualenv --no-site-packages venv
The --no-site-packages flag is deprecated; it is now the default behavior.
Using real prefix 'C:\\Program Files (x86)\\Python'
New python executable in venv\Scripts\python.exe
File venv\Lib\distutils\distutils.cfg exists with different content; not overwri
ting
Installing setuptools.................done.
Installing pip...................done.

c:\testdjangoproj\mysite>source venv/bin/activate
'source' is not recognized as an internal or external command,
operable program or batch file.

c:\testdjangoproj\mysite>source venv/bin/activate
'source' is not recognized as an internal or external command,
operable program or batch file.

c:\testdjangoproj\mysite>source mysite/bin/activate
'source' is not recognized as an internal or external command,
operable program or batch file.

c:\testdjangoproj\mysite>

当前回答

如果您使用的是windows操作系统,那么在git终端中使用以下命令$source venv/Scripts/activate。这将帮助您进入虚拟环境。

其他回答

最好的方法是,使用向后斜杠,并在activate末尾使用.bat

C:\Users>your_env_name\Scripts\activate.bat

一个小提示,但我在Win10 cmd上的斜杠方式错误。根据python文档,激活命令是:C:\> <venv>\Scripts\activate.bat 当你浏览目录时,比如cd .env/Scripts

因此,为了创建我的venv,我使用python -m venv—拷贝。env并激活。env\Scripts\activate.bat

在windows上使用Python3激活virtualenv的步骤如下:

Python3 -m venv env \ env \ bin \激活

如果您使用的是windows操作系统,那么在git终端中使用以下命令$source venv/Scripts/activate。这将帮助您进入虚拟环境。

如果想要在Windows上打开虚拟环境,那么只需要记住一件事,在给出路径时使用向后斜杠而不是向前斜杠。

这是正确的:

D:\xampp\htdocs\htmldemo\python-virtual-environment>env\Scripts\activate

这是错误的:

D:\xampp\htdocs\htmldemo\python-virtual-environment>env/Scripts/activate