Use different Python version with virtualenv


I have a Debian system currently running with python 2.5.4. I got virtualenv properly installed, everything is working fine. Is there a possibility that I can use a virtualenv with a different version of Python?

I compiled Python 2.6.2 and would like to use it with some virtualenv. Is it enough to overwrite the binary file? Or do I have to change something in respect to the libraries?

5/28/2010 3:24:40 AM

Accepted Answer

Just use the --python (or short -p) option when creating your virtualenv instance to specify the Python executable you want to use, e.g.:

virtualenv --python=/usr/bin/python2.6 <path/to/new/virtualenv/>

N.B. For Python 3.3 or later, refer to The Aelfinn's answer below.

12/4/2018 7:54:29 PM

UPDATE: For Python3.6, the below pyvenv script is deprecated. Instead, the Python Docs suggest creating the virtual environment with the following command:

python3 -m venv <myenvname>

For python3 (3.3+), use either the above method or the script pyvenv command.

pyvenv /path/to/new/virtual/environment

Please note that venv does not permit creating virtualenv with other versions of Python. For that, install and use the virtualenv package.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow