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

当前回答

以管理员身份打开powershell 输入“Set-ExecutionPolicy remotessigned -Force” “gpedit运行。>管理模板>Windows组件>Windows Powershell 寻找“激活脚本执行”并将其设置为“激活” 设置执行指令为“允许全部” 应用 刷新你的环境

其他回答

使用任何github控制台打开该文件夹。 例如使用visualCode和Gitbash控制台程序: 1)为windows安装Gitbash

2)使用VisualCode IDE,右键单击项目在终端控制台打开选项

3)在Visualcode的窗口控制台,寻找一个Select->默认shell,并将其更改为giitbash

4)现在你的项目是打开bash控制台和正确的路径,放入source ./Scripts/activate

顺便说一句:。空格= source

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

venv脚本/ activate

如果你在使用virtualenv yourenvname命令后看到5个文件夹(Include,Lib,Scripts,tcl,pip-selfcheck),将目录更改为cmd本身的Scripts文件夹,并简单地使用“activate”命令。

使用这些它为meenv\脚本\激活工作

source是一个shell命令,专为运行在Linux(或任何Posix,但不管怎样,不是Windows)上的用户而设计。

在Windows上,virtualenv会创建一个.bat/。ps1文件,所以你应该运行venv\Scripts\activate代替(根据virtualenv文档的激活脚本)。

只需运行activate,不需要扩展名,这样无论您使用cmd.exe还是PowerShell,都将使用正确的文件。