2012-01-19 118 views
44

我在我的項目周圍創建了virtualenv,但是當我嘗試激活它時,我無法啓動。 它可能只是語法或文件夾位置,但我現在很難。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> 
+0

本文檔確實有助於出了POSIX和Windows系統:https://virtualenv.pypa.io/en/stable/userguide/ – Blairg23

回答

161

source是一個shell命令專爲在Linux上運行的用戶(或任何Posix的,但不管,而不是Windows)。

在Windows上,virtualenv創建一個批處理文件,因此您應該運行venv\Scripts\activate.bat(根據virtualenv documentation on the activate script)。

+2

你釘它約翰,謝謝 ! – user1157538

+0

+1謝謝約翰。我遇到了完全相同的問題。 – Anthony

+0

工程就像一個魅力!謝謝:) –

0

我有一段時間在使用git bash的windows上使用virtualenv,我通常最終明確地指定了python二進制文件。

如果我的環境在說.env我會打電話python通過./.env/Scripts/python.exe …,或在shebang行#!./.env/Scripts/python.exe;

假設你的工作目錄包含你的virtualenv(.env)。

1
  1. 對於激活您可以通過cd venv轉到venv你的virtualenv目錄 。

  2. 然後鍵入ls命令, 你會得到5個文件夾includeLibScriptstcl和60 pip_selfcheck.json

  3. 現在鍵入./Scripts/activate來激活您的virtualenv venv

您的提示將更改爲表明您現在正在虛擬環境中運行。它看起來像這樣(venv)[email protected]:~/venv$

祝賀..

和你venv現在被激活。

0

您可以Cygwin的終端上運行source命令