Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a virtualenv with both python2 and python3

Tags:

I tried to use virtualenvwrapper to create a virtualenv with both python2 and python3

Per virtualenv with python2 and python3 via Homebrew I hoped this would work:

(The name of the virtualenv is 'double')

mkvirtualenv double -p `which python`
mkvirtualenv double -p `which python3`

It mentions that

Not overwriting existing python script both/bin/python (you must use both/bin/python3.4)

But it that does not seem to be true. Typing python python2.7 python3 and python3.4 all start the python3.4 interpreter.

like image 294
Zweedeend Avatar asked Nov 06 '14 14:11

Zweedeend


People also ask

Can you have Python 2 and 3 at the same time?

We can have both Python 2 and Python 3 installed on any Windows or Linux device. We can either create different environments on different IDEs to use the versions separately or use the following ways to run them using the command prompt.

Can I install different Python version in virtualenv?

It's still possible to use a different python version with venv . Instead of providing an argument, like with virtualenv , you just be sure to use the appropriate python version to run venv .

How do I create a Python 2.7 environment?

Found a workaround to use Spyder on python 2.7. setup two virtual environments for Python 2.7 and 3.6. Launce anaconda navigator and install spyder 3.3. 6 on both the environments Launch spyder on the environment with Python 3.6 Preferences-->Python Interpreter --> set the Python path for 2.7 Restart Spyder Done!


2 Answers

Sorry, virtualenv is designed to support single interpreter version.

If you need to use several python versions on the same codebase please create separate virtual environments.

like image 160
Andrew Svetlov Avatar answered Oct 28 '22 03:10

Andrew Svetlov


virtualenv does not support multiple interpreter versions . My suggestion is to use different environment for each of the versions :

virtualenv -p /usr/bin/python3.3 py3env
virtualenv -p /usr/bin/python py2env
like image 25
Alexander Avatar answered Oct 28 '22 02:10

Alexander