问题
I have this installed
- on Windows 7
- Python 2.7.6 (my default, with virtualenv installed)
- Python 2.4.4
- Python 2.5.4
- Python 2.6.6
- Python 3.3.3
- virtualenv 1.10.1
I want to test code on all of those python installations.
(Similar quesion Multiple python versions using virtualenv -p (and virtualenvwrapper-win) on Windows does not answer this.)
This is what I tried so far:
Python 2.4 gives a syntax error (creates an environment but with PY27 installed!):
>virtualenv -p c:\apps\Python24\python.exe env24_v
Running virtualenv with interpreter c:\apps\Python24\python.exe
File "C:\apps\Python27\lib\site-packages\virtualenv.py", line 1508
cp_or_ln = (os.symlink if symlink else copyfile)
^
SyntaxError: invalid syntax
Python 2.5 is obviously not supported (no environment created):
C:\Users\martin>virtualenv -p c:\apps\Python25\python.exe env25
Running virtualenv with interpreter c:\apps\Python25\python.exe
ERROR: None
ERROR: this script requires Python 2.6 or greater.
Python 2.6 works as expected:
C:\Users\martin\.virtualenvs>virtualenv -p c:\apps\Python26\python.exe env26
Running virtualenv with interpreter c:\apps\Python26\python.exe
New python executable in env26\Scripts\python.exe
Installing Setuptools..............done.
Installing Pip.............done.
C:\Users\martin\.virtualenvs>env26\Scripts\activate
(env26) C:\Users\martin\.virtualenvs>python
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
Python 2.7 and 3.3 also work as expected.
So my question is: Although the recent virtualenv tool does not support Python 2.4 / 2.5 environments, is there a trick to achieve this?
回答1:
You need old version virtualenv version < 1.8
virtualenv version 1.7 can be downloaded from (https://pypi.python.org/pypi/virtualenv/1.7).
However, you don't need to install that version, but just need to use virtualenv.py inside of package. What this means is running virtualenv.py by your default python (python2.7)
on Linux / Mac, command will be like below
python /{download folder path}/virtualenv-1.7/virtualenv.py -p python2.4 {wanted environment name}
For your case, environment is windows and if Python2.7 path is set as environment variable and also assume that you download virtualenv-1.7.tar.gz under c:\temp, then below is the exact command you want to run after unarchiving it.
C:\Users\martin> python C:\temp\virtualenv-1.7\virtualenv.py -p C:\apps\Python24\python.exe env24_v
来源:https://stackoverflow.com/questions/20584478/how-do-i-setup-virtualenv-environments-for-python-2-4-and-2-5-versions-on-window