我安装了 64 位 Python (2.7.5)C:\Python27
和 32 位 Python C:\Python27_32
。
我想使用 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:\Python27
为C:\Python27_32
,那么我就无法运行 virtualenv(ImportError: No module named pkg_resources
)。
这是我第一次弄乱 virtualenv,所以我确定我缺少一些基本的东西。如何创建使用 32 位 Python 安装的虚拟环境?