我创建了一个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>

当前回答

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

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

其他回答

我在自己的Windows 10电脑上也遇到了同样的问题。 我尝试的步骤是:

去andconda终端 步骤1

pip3 install -U pip virtualenv

步骤2

virtualenv --system-site-packages -p python ./venv

or

virtualenv --system-site-packages -p python3 ./venv

步骤3

.\venv\activate

你可以通过anaconda中的蜘蛛工具输入import tensorflow as tf来检查它

确保有venv,并遵循下面的命令。它适用于Windows 10。

转到您希望虚拟环境驻留的路径:

> cd <my_venv_path>

创建虚拟环境“env”:

> python -m venv env 

添加路径到git忽略文件(可选):

> echo env/ >> .gitignore

激活虚拟环境:

> .\env\Scripts\activate

导航到您的virtualenv文件夹例如..\project1_env> 然后输入

源脚本/激活

如. .脚本/激活\ project1_env >来源

:: location of bat file
::C:\Users\gaojia\Dropbox\Projects\free_return\venv\Scripts\activate.bat 
:: location of the cmd bat file and the ipython notebook
::C:\Users\gaojia\Dropbox\Projects\free_return\scripts\pre_analysis
source ..\..\venv\Scripts\activate
PAUSE
jupyter nbconvert --to html --execute consumer_response_DID.ipynb
PAUSE

上面是我的bat文件,我试图通过它来执行一个ipython笔记本。但cmd窗口给我什么,并立即关闭,任何建议为什么会发生这种情况?

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

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