问题
My virtualenv is currently configured to python 3.5.0 while the package I need to use only supports 2.7. I need a way of downgrading my python runtime to 2.7 within my virtualenv.
I do have both versions available to use: First one is in my virtualenv, second is computer-wide.
(project) me-Air:element me$ python -V
Python 3.5.0
me-Air:element me$ python -V
Python 2.7.10
回答1:
You cannot "downgrade" virtualenv.
You will have to create a new one, you don't necessarily need to delete your current one unless you want the virtualenv to have the same name as your current one.
virtualenv -p /usr/bin/python2.7 <path/to/new/virtualenv/>
Since your problem requires them to be integrated there are many ways to do it, use subprocess to do whatever you need to with the Python 2.7 code and transfer the output back to your Python 3 code.
You could also use Rabbit MQ Queues to transfer data to and from the programs running different versions of Python.
回答2:
Another method of pinning a virtualenv to a specific Python version is to run it via the -m
flag on the Python executable. E.g.
python2 -m virtualenv ./venv
Likewise, if you wanted a Python 3 virtualenv, you'd run this:
python3 -m virtualenv ./venv
来源:https://stackoverflow.com/questions/42221341/downgrade-virtualenv-to-2-7-from-3-5-3