Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use virtualenv to use 32-bit and 64-bit Python in Windows?

I have 64-bit Python (2.7.5) installed at C:\Python27 and 32-bit Python at C:\Python27_32.

I would like to use virtualenv to set up a 32-bit virtual environment that I can switch into when I need to use 32-bit Python. Once that environment is set up, I plan to edit the bin\activate file to change all the necessary paths to point to the 32-bit directories.

However, when I try to create the virtual environment, I get the following error:

> 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

It seems to be doing imports in the 64-bit folder instead of in the 32-bit folder. I'm not sure if it's because of the way my environment variables are set up, or because I installed virtualenv under 64-bit Python in the first place.

These are my user environment variables:

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

But if I change every C:\Python27 to C:\Python27_32 in my environment variables, then I can't virtualenv to run (ImportError: No module named pkg_resources).

This is my first time messing with virtualenv, so I'm sure I'm missing something basic. How can I create a virtual environment that uses my 32-bit Python installation?

like image 239
capitalistcuttle Avatar asked Dec 21 '22 02:12

capitalistcuttle


1 Answers

For your virtual env to run after you have changed your paths you will need to install virtualenv into the 32 bit python - there is nothing stopping you having a copy of virtualenv in each python.

Assuming you have python 2.7.c 64-bit as your default python and you have also installed python 2.7.x 32-bit you would need both anyway - also assuming that you are on windows your two pythons will be installed somewhere like:

C:\Python27 and C:\Python27_64

With the latter on your path.

Also assuming that you have pip installed in both, you will need it for virtualenv anyway - to install virtualenv to the 32 bit python you can either run:

Path\To\32Bit\pip install virtualenv

or

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
like image 120
Steve Barnes Avatar answered Dec 31 '22 13:12

Steve Barnes