Use different Python version with virtualenv
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 5 Looping
--
Chapters
00:00 Use Different Python Version With Virtualenv
00:10 Accepted Answer Score 2002
00:34 Answer 2 Score 643
00:59 Answer 3 Score 228
01:43 Answer 4 Score 216
02:28 Answer 5 Score 116
02:35 Thank you
--
Full question
https://stackoverflow.com/questions/1534...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #virtualenv #virtualenvwrapper
#avk47
ACCEPTED ANSWER
Score 2025
NOTE: For Python 3.3+, see The Aelfinn's answer below.
Use the --python (or short -p) option when creating a virtualenv instance to specify the Python executable you want to use, e.g.:
virtualenv --python="/usr/bin/python2.6" "/path/to/new/virtualenv/"
ANSWER 2
Score 712
Since Python 3.3, the documentation suggests creating the virtual environment using stdlib:
python3 -m venv "my_env_name"
Also, if we want a particular version of python, lets say 3.6, then we can use
python3.6 -m venv "my_env_name"
Make sure to install the referenced version of Python along with your existing system Python.
ANSWER 3
Score 230
These are the steps you can follow when you are on a shared hosting environment and need to install & compile Python from source and then create venv from your Python version. For Python 2.7.9. you would do something along these lines:
mkdir ~/src
wget http://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz
tar -zxvf Python-2.7.9.tgz
cd Python-2.7.9
mkdir ~/.localpython
./configure --prefix=$HOME/.localpython
make
make install
virtual env
cd ~/src
wget https://pypi.python.org/packages/5c/79/5dae7494b9f5ed061cff9a8ab8d6e1f02db352f3facf907d9eb614fb80e9/virtualenv-15.0.2.tar.gz#md5=0ed59863994daf1292827ffdbba80a63
tar -zxvf virtualenv-15.0.2.tar.gz
cd virtualenv-15.0.2/
~/.localpython/bin/python setup.py install
virtualenv ve -p $HOME/.localpython/bin/python2.7
source ve/bin/activate
Naturally, this can be applicable to any situation where you want to replicate the exact environment you work and deploy on.
ANSWER 4
Score 116
virtualenv --python=/usr/bin/python2.6 <path/to/myvirtualenv>