我创建了一个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”,然后回到你试图运行venv激活的地方,它应该可以工作:)

链接到解释更详细内容的文章: https://www.stanleyulili.com/powershell/solution-to-running-scripts-is-disabled-on-this-system-error-on-powershell/

其他回答

如果您使用的是windows,只需运行。\Scripts\activate。注意,反斜杠会起作用!

对于windows,在不带引号的终端中输入“C:\Users\Sid\venv\FirstProject\Scripts\activate”。只需给出项目中脚本文件夹的位置。因此,该命令将是location_of_the_Scripts_Folder\activate。

如果你使用的是Windows,使用命令“venv\Scripts\activate”(不带source)来激活虚拟环境。如果使用PowerShell,可能需要将Activate大写。

为了激活你可以去venv你的virtualenv目录 通过CD venv。 然后在Windows上,键入dir(在unix上,键入ls)。 你会得到5个文件夹,包括Lib, Scripts, tcl和60 现在输入。\Scripts\activate激活你的virtualenv venv。

您的提示符将更改为指示您现在正在虚拟环境中操作。它看起来像这样(venv)user@host:~/venv$。

你的venv现在被激活了。

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

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

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

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

顺便说一句:。空格= source