Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 320
Ulf Avatar asked Oct 07 '09 21:10

Ulf


People also ask

Can I install different Python version in virtualenv?

Installing Virtualenv using pip3You must first install a custom version of Python 3. This custom installation of Python 3 will also contain pip3. After it's installed and activated, run the which python3 command as shown in the article. This should return the location of your custom version of Python 3.

Which Python version does virtualenv use?

Creating a Python Virtual Environment virtualenv supports older Python versions and needs to be installed using the pip command. In contrast, venv is only used with Python 3.3 or higher and is included in the Python standard library, requiring no installation.


1 Answers

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.

like image 84
Daniel Roseman Avatar answered Oct 20 '22 00:10

Daniel Roseman