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

当前回答

我也有同样的问题。我使用的是Python 2、Windows 10和Git Bash。在Git Bash中,你需要使用:

 source venv/Scripts/activate

其他回答

如果你只在Windows 10中CD你的项目类型

Scripts/activate

这对我来说很有用:)

对于windows微软技术支持,可能是执行策略设置有问题。要修复它,您应该尝试执行 Set-ExecutionPolicy无限制-Scope进程

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

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

已经有一段时间没有使用Django了,所以当我回到我的旧项目时,我在Windows 10上遇到了同样的问题 这对我很有用:

venv脚本/ activate

有些人有问题与vscode我假设所有上述方法不工作。

这只是因为默认情况下vscode使用powershell而不是cmd… 单击它旁边的小箭头,选择CMD并运行命令。