2013-07-22 184 views
1

我在C:\Python27上安裝了64位Python(2.7.5),在C:\Python27_32上安裝了32位Python。如何使用virtualenv在Windows中使用32位和64位Python?

我想使用virtualenv設置一個32位的虛擬環境,當我需要使用32位Python時,可以切換到這個環境。一旦設置了該環境,我打算編輯bin\activate文件以將所有必需的路徑更改爲指向32位目錄。

然而,當我嘗試創建虛擬環境中,我得到以下錯誤:

> virtualenv --python=C:\Python27_32\python.exe foo 

Running virtualenv with interpreter C:\Python27_32\python.exe 
PYTHONHOME is set. You *must* activate the virtualenv before using it 
New python executable in foo\Scripts\python.exe 
Installing setuptools............... 
    Complete output from command C:\Users\<user>\Drop...o\Scripts\python.exe -c "#!python 
\"\"\"Bootstra...sys.argv[1:]) 

" C:\Python27\lib\site...ols-0.6c11-py2.7.egg: 
    Traceback (most recent call last): 
    File "<string>", line 278, in <module> 
    File "<string>", line 238, in main 
    File "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", line 21, in <module> 
    File "build/bdist.linux-i686/egg/setuptools/package_index.py", line 2, in <module> 
    File "C:\Python27\Lib\urllib2.py", line 94, in <module> 
    import httplib 
    File "C:\Python27\Lib\httplib.py", line 71, in <module> 
    import socket 
    File "C:\Python27\Lib\socket.py", line 47, in <module> 
    import _socket 
ImportError: DLL load failed: %1 is not a valid Win32 application. 
---------------------------------------- 
...Installing setuptools...done. 
Traceback (most recent call last): 
    File "C:\Python27\lib\site-packages\virtualenv.py", line 2577, in <module> 
    main() 
    File "C:\Python27\lib\site-packages\virtualenv.py", line 979, in main 
    no_pip=options.no_pip) 
    File "C:\Python27\lib\site-packages\virtualenv.py", line 1091, in create_environment 
    search_dirs=search_dirs, never_download=never_download) 
    File "C:\Python27\lib\site-packages\virtualenv.py", line 611, in install_setuptools 
    search_dirs=search_dirs, never_download=never_download) 
    File "C:\Python27\lib\site-packages\virtualenv.py", line 583, in _install_req 
    cwd=cwd) 
    File "C:\Python27\lib\site-packages\virtualenv.py", line 1057, in call_subprocess 
    % (cmd_desc, proc.returncode)) 
OSError: Command C:\Users\<user>\Drop...o\Scripts\python.exe -c "#!python 
\"\"\"Bootstra...sys.argv[1:]) 

" C:\Python27\lib\site...ols-0.6c11-py2.7.egg failed with error code 1 

這似乎是在做64位的文件夾,而不是在32位夾進口。我不確定是因爲我的環境變量設置的方式,還是因爲我首先在64位Python下安裝了virtualenv。

這些都是我的用戶環境變量:

Path: %PYTHONHOME%;C:\Python27\Scripts 
PYTHONHOME: C:\Python27 
PYTHONPATH: C:\Python27\Lib;C:\Python27\Lib\lib-tk;C:\Python27\DLLs; 

但是,如果我在環境變量改變每C:\Python27C:\Python27_32,那麼我不能VIRTUALENV運行(ImportError: No module named pkg_resources)。

這是我第一次搞錯了virtualenv,所以我確定我錯過了一些基本的東西。我如何創建一個使用我的32位Python安裝的虛擬環境?

回答

7

爲了讓您的虛擬環境在更改路徑後運行,您需要將virtualenv安裝到32位python中 - 沒有任何東西阻止您在每個python中使用virtualenv的副本。

假設你有蟒蛇2.7.c 64位爲默認Python和還安裝了蟒蛇2.7.x 32位就需要兩個反正 - 也假設你對你的兩條蟒蛇將窗戶地方安裝,如:

C:\Python27C:\Python27_64

與後者的路徑上。

而且假設你已經PIP同時安裝在,你會需要它的virtualenv反正 - 到的virtualenv安裝到32位的蟒蛇,你可以運行:

Path\To\32Bit\pip install virtualenv 

set path=C:\Python27;C:\Python27\Scripts;%path% 
rem The above should set your 32 bit to be found before your 64 bit 
pip install virtualenv 
+1

謝謝史蒂夫。這工作。有關於路徑的問題,但會單獨詢問。 – capitalistcuttle

+0

很高興聽到它。 –

+0

你怎麼才能真正安裝虛擬環境到32位的Python? – JPC

相關問題