Virtual environment for a project that uses both python 2 and 3?

Viewed 321

I'm working on a big project (mostly C/C++) that has some python stuff in it. Most of the python stuff is based on python3, but some legacy code runs on python2. Does somebody here knows about a virtual environment tool that supports multiple versions of python at the same time? I've tried venv, virtualwnv, pyenv, pipenv with no luck. They all rely on having a single version of python on them. I would need to be able ti specify in the virtual environment a python2 and a python3, just like I do on the system install.

Thanks.

2 Answers

I recommend you to use Anaconda as it enables using different python versions in different environments, which you can specify at your own.

I created a blogpost about creating an environment with Anaconda, just create two different environments, one with python2.x and one with python3.x:

conda create -n python2env python=3.7
conda create -n python3env python=2.7

Virtualenvs simply can't be shared across Python versions - not even minor versions (3.x), much less Py2 and Py3 at the same time.

For a project that has bits in Python 2 and Python 3, you will need two virtualenvs, e.g.

python2 -m virtualenv py2_venv
python3 -m virtualenv py3_venv

or however you like.

Related