简体   繁体   中英

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 (eg 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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM