Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the standard way to handle 32 bit and 64 bit Python installations side-by-side on a Windows machine?

I would like to install 32 bit and 64 bit versions of Python on a Windows machine side-by-side. The default directory is c:\Python?? for both so I would have to modify one or both of the install directories. I'm curious to see what the "standard" way is to support both versions?

like image 984
Michael Kelley Avatar asked Feb 17 '12 21:02

Michael Kelley


People also ask

Can you have 2 versions of Python installed?

If you wish to use multiple versions of Python on a single machine, then pyenv is a commonly used tool to install and switch between versions. This is not to be confused with the previously mentioned depreciated pyvenv script. It does not come bundled with Python and must be installed separately.


2 Answers

Since my 32-bit Python kept looking in 64-bit directories, I added the following line before importing things,

import sys
sys.path = [r'C:\Python27-32',r'C:\Python27-32\Lib\site-packages'] + sys.path

and that usually worked.

In order to install something that I could not find on Christoph Gohlke's Unnoficial Windows Binaries for Python Extension Packages, I would do he following:

  1. Change the order of my environment variables in my Advanced System Settings, so that the preferred Python version shows up first, e.g., make sure that in Path and PYTHONPATH, C:\Python27-32;C:\Python27-32\Scripts; shows up before C:\Python27-64;C:\Python27-64\Scripts; if you're trying to install something that is 32-bit.
  2. Go to the directory containing the setup.py file that you want to install
  3. Start the 32-bit interpreter, i.e., run C:\Python27-32\python.exe at the command line
  4. Type import sys, os
  5. Type sys.path = [r'C:\Python27-32',r'C:\Python27-32\Lib\site-packages'] + sys.path
  6. Type os.system( r'C:\Python27-32\python.exe setup.py install' )

And that should work, hopefully.

like image 167
cjohnson318 Avatar answered Sep 29 '22 22:09

cjohnson318


Virtualenv might help here. I personally just use a non-default folder for install, like I have c:\Python27-64 and c:\Python32-64 and c:\python26-32 on my machine.

Then I have bat files in my path like py26.bat and py27.bat and py32.bat, but sometimes it's not pretty. Also, some packages with installers really try to look in the registry for things and I can only get them to install to a single instance.

Obviously, I don't have a perfect solution.

like image 29
jgritty Avatar answered Sep 29 '22 23:09

jgritty