Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set up multiple python installations on windows with tox

I am trying to set up tox on windows to run tests against multiple python installations. I have installed each python in folders named, C:\Python\PythonXX_YY, XX is the python version (e.g. 27) and YY is either 32 or 64. Currently, the only python in my PATH is C:\Python\Python33_64, since I use the new python launcher to run whichever version I want. I am also running tox from this version.

The first problem is that tox doesn't detect these installations, presumably because they are not in the default locations. I can get around this by setting the path in tox.ini for each environment, but it makes the setup very specific to my computer. Is there a better way of letting tox know where my pythons are globally?

The second problem is that, setting the python locations in tox.ini, I get the following error when I run it (for Python27):

Traceback (most recent call last):
  File "c:\Python\Python33_64\lib\site-packages\virtualenv.py", line 2557, in <module>
    main()
  File "c:\Python\Python33_64\lib\site-packages\virtualenv.py", line 961, in main
    never_download=options.never_download)
  File "c:\Python\Python33_64\lib\site-packages\virtualenv.py", line 1062, in create_environment
    site_packages=site_packages, clear=clear))
  File "c:\Python\Python33_64\lib\site-packages\virtualenv.py", line 1255, in install_python
    copy_required_modules(home_dir)
  File "c:\Python\Python33_64\lib\site-packages\virtualenv.py", line 1193, in copy_required_modules
    dst_filename = change_prefix(filename, dst_prefix)
  File "c:\Python\Python33_64\lib\site-packages\virtualenv.py", line 1164, in change_prefix
    (filename, prefixes)
AssertionError: Filename c:\Python\Python33_64\lib\site-packages\readline.py does not start with any of these prefixes: ['c:\\python\\python27_64']

ERROR: InvocationError: c:\python\python27_64\python.exe c:\Python\Python33_64\lib\site-packages\virtualenv.py --distribute py27 (see C:\Users\david.townshend\Documents\Global\Programming\norman\.tox\py27\log\py27-0.log)

It looks like its trying to install Python2.7 stuff from Python3.3, but I've never really used virtualenv much before so I might be mis-intepreting this error.

I'm not sure what the solution is to this, but it seems to me that the obvious solution should be for tox to use the python launcher to get the python version it needs. Is there a way to make it do this?

like image 496
aquavitae Avatar asked Dec 12 '12 06:12

aquavitae


People also ask

How do I install multiple versions of Python on Windows?

Install multiple python versions For Windows users, I recommend using the Windows x86-64 executable installer option if you work on a 64bit system. Otherwise, just use the Windows x86 executable installer . After locating the install option for the specific version, just press the download link.

Can I have multiple Python versions 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.

Should I use tox Python?

tox makes it easy to: Test against different versions of Python (which would have alerted Kyle that the library hadn't been tested against his install version). Test against different dependency versions. Capture and run setup steps/ad hoc commands (which Kyle could have made a mistake on / not known about)


2 Answers

Looks like tox looks for pythons at such locations:

m = re.match(r"python(\d)\.(\d)", name)
if m:
    # The standard names are in predictable places.
    actual = r"c:\python%s%s\python.exe" % m.groups()

So you should put your pythons at c:\Python3.3\ etc. Note the dot . instead of the underscore _. Though this is a pain.

like image 55
agroszer Avatar answered Oct 17 '22 03:10

agroszer


I'm not sure if Tox did this when the OP first asked the question but it seems one may now setup each environment individually as follows :

[tox]
envlist = pyw35,pyw36
skip_missing_interpreters=True

[testenv]
commands = {envpython} setup.py test

[testenv:pyw35]
basepython = C:/Python/64bit/351/python.exe

[testenv:pyw36]
basepython = C:/Python/64bit/362/python.exe

user330612 provides a variation upon this, but I personally could not get it to work.

[testenv]
commands = {envpython} setup.py test
basepython=
   pyw35: C:/Python/64bit/351/python.exe
   pyw36: C:/Python/64bit/362/python.exe
like image 3
Carel Avatar answered Oct 17 '22 05:10

Carel