Use different Python version with virtualenv Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How to create a virtual environment for a specific version of Python?Multiple versions of pythonSetting Non-default-python-version in virtualenvHow Do I Make A Django (Python) Project Use Only A Specific Interpreter?Virtualenv created a folder, but the result its not I wantedhow to install two development environmentsHow to use python3.5 with virtualenv, even if the system globally has 2.7Creating virtual environments for python 2.7 and python 3.4 on same windows 7 pcCreate virtualenv with a different python version than the system pythonHow to set python version 2.7.15 instead of 2.7.10 in virtualenvCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Difference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?How to leave/exit/deactivate a Python virtualenvDifference between __str__ and __repr__?Does Python have a string 'contains' substring method?Python and pip, list all versions of a package that's available?
Asymptotics question
Tannaka duality for semisimple groups
Can you force honesty by using the Speak with Dead and Zone of Truth spells together?
Found this skink in my tomato plant bucket. Is he trapped? Or could he leave if he wanted?
Relating to the President and obstruction, were Mueller's conclusions preordained?
If Windows 7 doesn't support WSL, then what is "Subsystem for UNIX-based Applications"?
Why complex landing gears are used instead of simple,reliability and light weight muscle wire or shape memory alloys?
What is chord melody?
Is there hard evidence that the grant peer review system performs significantly better than random?
Did pre-Columbian Americans know the spherical shape of the Earth?
Why weren't discrete x86 CPUs ever used in game hardware?
Why is a lens darker than other ones when applying the same settings?
Co-worker has annoying ringtone
Why shouldn't this prove the Prime Number Theorem?
A term for a woman complaining about things/begging in a cute/childish way
What order were files/directories output in dir?
Can an iPhone 7 be made to function as a NFC Tag?
What does Turing mean by this statement?
How to ask rejected full-time candidates to apply to teach individual courses?
what is the log of the PDF for a Normal Distribution?
I got rid of Mac OSX and replaced it with linux but now I can't change it back to OSX or windows
Is there public access to the Meteor Crater in Arizona?
Is it dangerous to install hacking tools on my private linux machine?
Printing attributes of selection in ArcPy?
Use different Python version with virtualenv
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How to create a virtual environment for a specific version of Python?Multiple versions of pythonSetting Non-default-python-version in virtualenvHow Do I Make A Django (Python) Project Use Only A Specific Interpreter?Virtualenv created a folder, but the result its not I wantedhow to install two development environmentsHow to use python3.5 with virtualenv, even if the system globally has 2.7Creating virtual environments for python 2.7 and python 3.4 on same windows 7 pcCreate virtualenv with a different python version than the system pythonHow to set python version 2.7.15 instead of 2.7.10 in virtualenvCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Difference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?How to leave/exit/deactivate a Python virtualenvDifference between __str__ and __repr__?Does Python have a string 'contains' substring method?Python and pip, list all versions of a package that's available?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
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?
python virtualenv virtualenvwrapper
add a comment |
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?
python virtualenv virtualenvwrapper
8
Just mentioning that you can do this using virtualenvwrapper too.
– bias
May 28 '10 at 3:25
9
Worth noting that in python 3, there is a built-in virtualenv equivalent: venv.
– naught101
Sep 1 '14 at 12:47
1
Is it not possible to switch python version in the current environment without creating a new environment?
– Charlie Parker
Aug 28 '16 at 23:38
add a comment |
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?
python virtualenv virtualenvwrapper
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?
python virtualenv virtualenvwrapper
python virtualenv virtualenvwrapper
edited May 28 '10 at 3:24
bias
1,05731731
1,05731731
asked Oct 7 '09 at 21:11
UlfUlf
5,03851513
5,03851513
8
Just mentioning that you can do this using virtualenvwrapper too.
– bias
May 28 '10 at 3:25
9
Worth noting that in python 3, there is a built-in virtualenv equivalent: venv.
– naught101
Sep 1 '14 at 12:47
1
Is it not possible to switch python version in the current environment without creating a new environment?
– Charlie Parker
Aug 28 '16 at 23:38
add a comment |
8
Just mentioning that you can do this using virtualenvwrapper too.
– bias
May 28 '10 at 3:25
9
Worth noting that in python 3, there is a built-in virtualenv equivalent: venv.
– naught101
Sep 1 '14 at 12:47
1
Is it not possible to switch python version in the current environment without creating a new environment?
– Charlie Parker
Aug 28 '16 at 23:38
8
8
Just mentioning that you can do this using virtualenvwrapper too.
– bias
May 28 '10 at 3:25
Just mentioning that you can do this using virtualenvwrapper too.
– bias
May 28 '10 at 3:25
9
9
Worth noting that in python 3, there is a built-in virtualenv equivalent: venv.
– naught101
Sep 1 '14 at 12:47
Worth noting that in python 3, there is a built-in virtualenv equivalent: venv.
– naught101
Sep 1 '14 at 12:47
1
1
Is it not possible to switch python version in the current environment without creating a new environment?
– Charlie Parker
Aug 28 '16 at 23:38
Is it not possible to switch python version in the current environment without creating a new environment?
– Charlie Parker
Aug 28 '16 at 23:38
add a comment |
21 Answers
21
active
oldest
votes
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.
151
I figured I'd mention that this works for virtualenvwrappers too: mkvirtualenv -p python2.6 env
– bias
May 28 '10 at 3:24
53
I'm missing something here - doesn't this require that 2.6 already be installed on the system? I thought the point of virtualenv was that I could have a version of python other than the main one (in my case, 2.4 on CentOS). I was assuming I could install virtualenv, then install Python 2.6 under it for packages in the env to make use of?
– John C
May 24 '11 at 14:31
36
@John yes, you are. That isn't the point of virtualenv: the point of that is to create a sandboxed environment for Python. You will need to install that version first - you can install it locally for your user, though.
– Daniel Roseman
May 24 '11 at 14:47
8
@JohnC You can use pythonbrew to install alternative pythons.
– ashwoods
Dec 1 '11 at 22:03
44
If you are a tad lazy:virtualenv -p `which python2.6` <path/to/new/virtualenv>
– blaze
Oct 16 '13 at 0:57
|
show 10 more comments
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.
5
Glad you pointed that out, it needs more promotion. One minor nit: they are now advocating running it aspython3 -m venv <envname>
to prevent needing stub scripts for everything.
– Paul Everitt
Nov 20 '16 at 16:08
5
In fact thepyvenv
script is deprecated in Python 3.6+, though the underlyingvenv
module itself is not. So usepython 3 -m venv <myenvname>
as @PaulEveritt says.
– RichVel
Dec 20 '16 at 8:47
3
Be warned thatpyvenv
orpython3 -m venv ...
do NOT install thepython-config
script. This means that even after activating your Python3 environment the system-widepython-config
will be invoked with confusing consequences. See this bug report from 2011 github.com/pypa/virtualenv/issues/169 and my question stackoverflow.com/questions/42020937/…
– Laryx Decidua
Feb 23 '18 at 11:16
add a comment |
These are steps when you are on shared hosting environment and need to install & complie 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.
2
Could you elaborate on why to do it that way: Why install python locally? And more importantly why install virtualenv using the python version you want to use with it?
– lajarre
Oct 8 '12 at 19:46
14
sure. If you are on virtual hosting environment and the server provides older versions of python that you are not happy with - that was my case scenario. Also if you happen to develop projects on different servers and you want to replicate these environments on your local machine.... Virtualenv creates hard links to python libs . so it's really important with version of python you are using to install and create Virtualenv from.
– zzart
Oct 11 '12 at 20:15
6
Or if you are like me and am on a locked down machine at work with no sudo privileges. Local copies of libraries, SQL databases, languages and compilers galore! Thanks!
– zachd1_618
Jan 24 '13 at 18:03
4
Under virtualenv 1.9.1, I had to use~/.localpython/bin/virtualenv
instead of justvirtualenv
for setup to complete without errors. In addition, usesource ve/bin/activate
instead ofsource activate
.
– Saul
Apr 10 '13 at 7:40
3
Another reason to do this would be to try out betas before they go main to make sure your projects and their dependencies still work without risking breaking your package management by clobbering something and leaving dangling files all over the place. I like this answer.
– RobotHumans
Dec 29 '13 at 14:02
|
show 4 more comments
virtualenv --python=/usr/bin/python2.6 <path/to/myvirtualenv>
2
See my answer below for an equivalent solution using environment variables. That approach means you don't have to remember to use-p
.
– Chris Johnson
Aug 5 '16 at 20:58
5
Is there no solutions that switches between python versions without requiring to create a new virtual environment?
– Charlie Parker
Aug 28 '16 at 22:27
Would this work, if you want to install a python version that is not installed on your system? Say you want to test outpython3.6
but dont want to touchpython3.5
installed on your computer?
– alpha_989
Jul 31 '18 at 3:53
add a comment |
There is an easier way,
virtualenv venv --python=python2.7
Thanks to a comment, this only works if you have python2.7 installed at the system level (e.g. /usr/bin/python2.7).
Otherwise, if you are using homebrew you can use the path to give you what you want.
virtualenv venv --python=/usr/local/bin/python
You can find the path to your python installation with
which python
This will also work with python 3.
which python3
>> /usr/local/bin/python3
virtualenv venv --python=/usr/local/bin/python3
Ultimately condensing to:
virtualenv venv -p `which python`
virtualenv venv -p `which python3`
1
FYI, only works if you have python2.7 installed at the system level (e.g. /usr/bin/python2.7)
– kingb12
Jan 27 '17 at 20:23
I was able to do this withvirtualenv venv --python=python3.6
as well
– Jordan
Sep 7 '17 at 18:03
You can actually drop the minor version number.virtualenv env --python=python2
– Anshul
Feb 5 '18 at 6:56
That's a proper solution, once you have all versions, you are interested in justing using the alias not the full path
– user1767754
Nov 20 '18 at 19:54
add a comment |
Under Windows for me this works:
virtualenv --python=c:Python25python.exe envname
without the python.exe
I got WindowsError: [Error 5] Access is denied
I have Python2.7.1 installed with virtualenv 1.6.1, and I wanted python 2.5.2.
add a comment |
Mac OSX 10.6.8 (Snow Leopard):
1) When you do pip install virtualenv
, the pip command is associated with one of your python versions, and virtualenv
gets installed into that version of python. You can do
$ which pip
to see what version of python that is. If you see something like:
$ which pip
/usr/local/bin/pip
then do:
$ ls -al /usr/local/bin/pip
lrwxrwxr-x 1 root admin 65 Apr 10 2015 /usr/local/bin/pip ->
../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pip
You can see the python version in the output.
By default, that will be the version of python that is used for any new environment you create. However, you can specify any version of python installed on your computer to use inside a new environment with the -p flag
:
$ virtualenv -p python3.2 my_env
Running virtualenv with interpreter /usr/local/bin/python3.2
New python executable in my_env/bin/python
Installing setuptools, pip...done.
virtualenv my_env
will create a folder in the current directory which
will contain the Python executable files, and a copy of the pip
[command] which you can use to install other packages.
http://docs.python-guide.org/en/latest/dev/virtualenvs/
virtualenv
just copies python from a location on your computer into the newly created my_env/bin/ directory.
2) The system python is in /usr/bin
, while the various python versions I installed were, by default, installed into:
/usr/local/bin
3) The various pythons I installed have names like python2.7
or python3.2
, and I can use those names rather than full paths.
========VIRTUALENVWRAPPER=========
1) I had some problems getting virtualenvwrapper to work. This is what I ended up putting in ~/.bash_profile
:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/django_projects #Not very important -- mkproject command uses this
#Added the following based on:
#http://stackoverflow.com/questions/19665327/virtualenvwrapper-installation-snow-leopard-python
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python2.7
#source /usr/local/bin/virtualenvwrapper.sh
source /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh
2) The -p option
works differently with virtualenvwrapper: I have to specify the full path to the python interpreter to be used in the new environment(when I do not want to use the default python version):
$ mkvirtualenv -p /usr/local/bin/python3.2 my_env
Running virtualenv with interpreter /usr/local/bin/python3
New python executable in my_env/bin/python
Installing setuptools, pip...done.
Usage: source deactivate
removes the 'bin' directory of the environment activated with 'source
activate' from PATH.
Unlike virtualenv, virtualenvwrapper will create the environment at the location specified by the $WORKON_HOME environment variable. That keeps all your environments in one place.
which pip
doesn't tell me the version of Python. It gives me this-/usr/local/bin/pip
.
– Sankalp
Mar 16 '18 at 2:36
@Sankalp, If you cd to/usr/local/bin
and do$ ls -al pip
, you should see something like:pip -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pip
– 7stud
Mar 16 '18 at 2:44
Already somewhat noted in answer, butmkproject
is the command to use if you want it to create both the project directory and a virtual environment of a given python version.mkproject -p /usr/bin/python3.6 myNewPython36Project
– Jim Factor
Jan 24 at 5:13
add a comment |
Suppose you currently have python 2.7 installed in your virtualenv. But want to make use of python3.2
, You would have to update this with:
$ virtualenv --python=/usr/bin/python3.2 name_of_your_virtualenv
Then activate your virtualenv by:
$ source activate name_of_your_virtualenv
and then do: python --version
in shell to check whether your version is now updated.
See my answer below for an equivalent solution using environment variables. That approach means you don't have to remember to use-p
.
– Chris Johnson
Aug 5 '16 at 20:58
add a comment |
These two commands should work fine for a newbie
virtualenv -p python2 myenv
(For python2)
virtualenv -p python3 myenv
(For python3)
1
The flag -p python2 works equivalent to looking for /usr/bin/python2. Use : virtualenv -p python2.7 myenv for 2.7 etc.
– Yash Sharma
Dec 28 '18 at 2:05
add a comment |
You can call virtualenv
with python version you want. For example:
python3 -m virtualenv venv
Or alternatively directly point to your virtualenv path. e.g. for windows:
c:Python34Scriptsvirtualenv.exe venv
And by running:
venv/bin/python
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
you can see the python version installed in virtual environment
I got this error on running the first command /usr/local/bin/python3: No module named virtualenv
– tanvi
May 23 '16 at 13:48
2
@tanvi : You need to install virtualenv into your python3 first. Runpip3 install virtualenv
first
– Nima Soroush
May 23 '16 at 14:30
add a comment |
The -p
approach works well, but you do have to remember to use it every time. If your goal is to switch to a newer version of Python generally, that's a pain and can also lead to mistakes.
Your other option is to set an environment variable that does the same thing as -p
. Set this via your ~/.bashrc
file or wherever you manage environment variables for your login sessions:
export VIRTUALENV_PYTHON=/path/to/desired/version
Then virtualenv
will use that any time you don't specify -p
on the command line.
This worked beautifully. Any idea why settingexport VIRTUALENVWRAPPER_PYTHON=/path/to/desired/version
per the virtualenvwrapper docs didn't work but this solution did work?
– YPCrumble
Nov 8 '16 at 22:37
That env var controls which Pythonvirtualenvwrapper
uses when run, nothing to do with installs.
– Chris Johnson
Nov 9 '16 at 1:47
This worked for me. No longer have to use -p every time I create a new virtualenv. Thanks!
– nedblorf
Apr 10 at 15:29
add a comment |
For Mac(High Sierra), install the virtualenv on python3 and create a virtualenv for python2:
$ python3 -m pip install virtualenv
$ python3 -m virtualenv --python=python2 vp27
$ source vp27/bin/activate
(vp27)$ python --version
Python 2.7.14
1
Install virtualenv on python3 if you don't have:python3 -m pip install virtualenv
– Howe
Jul 3 '18 at 15:47
add a comment |
On the mac I use pyenv and virtualenvwrapper. I had to create a new virtualenv. You need homebrew which I'll assume you've installed if you're on a mac, but just for fun:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install pyenv
pyenv install 2.7.10
pyenv global 2.7.10
export PATH=/Users/USERNAME/.pyenv/versions/2.7.10/bin:$PATH
mkvirtualenv -p ~/.pyenv/versions/2.7.10/bin/python virtual_env_name
I also froze my requirements first so i could simply reinstall in the new virtualenv with:
pip install -r requirements.txt
Command should bemkvirtualenv -p ~/.pyenv/versions/2.7.10/bin/python virtual_env_name
versions, not version. If SO allowed short edits, I woulda fixed it.
– Martin Burch
Sep 4 '15 at 4:30
pyenv
includes virtualenv support through thepyenv-virtualenv
plugin, so I find I don't really need virtualenvwrapper. More details in my pyenv answer.
– RichVel
May 7 '17 at 7:26
add a comment |
Even easier, by using command substitution to find python2 for you:
virtualenv -p $(which python2) <path/to/new/virtualenv/>
Or when using virtualenvwrapper :
mkvirtualenv -p $(which python2) <env_name>
add a comment |
In windows subsystem for linux:
Create environment for python3:
virtualenv --python=/usr/bin/python3 env
Activate it:
source env/bin/activate
add a comment |
Yes, the above answers are correct and works fine on Unix based systems like Linux & MAC OS X.
I tried to create virtualenv for Python2 & Python3 with the following commands.
Here I have used venv2 & venv3 as their names for Python2 & Python3 respectively.
Python2 »
MacBook-Pro-2:~ admin$ virtualenv venv2 --python=`which python2`
Running virtualenv with interpreter /usr/local/bin/python2
New python executable in /Users/admin/venv2/bin/python
Installing setuptools, pip, wheel...done.
MacBook-Pro-2:~ admin$
MacBook-Pro-2:~ admin$ ls venv2/bin/
activate easy_install pip2.7 python2.7
activate.csh easy_install-2.7 python wheel
activate.fish pip python-config
activate_this.py pip2 python2
MacBook-Pro-2:~ admin$
Python3 »
MacBook-Pro-2:~ admin$ virtualenv venv3 --python=`which python3`
Running virtualenv with interpreter /usr/local/bin/python3
Using base prefix '/Library/Frameworks/Python.framework/Versions/3.6'
New python executable in /Users/admin/venv3/bin/python3
Also creating executable in /Users/admin/venv3/bin/python
Installing setuptools, pip, wheel...done.
MacBook-Pro-2:~ admin$
MacBook-Pro-2:~ admin$ ls venv3/bin/
activate easy_install pip3.6 python3.6
activate.csh easy_install-3.6 python wheel
activate.fish pip python-config
activate_this.py pip3 python3
MacBook-Pro-2:~ admin$
Checking Python installation locations
MacBook-Pro-2:~ admin$ which python2
/usr/local/bin/python2
MacBook-Pro-2:~ admin$
MacBook-Pro-2:~ admin$ which python3
/usr/local/bin/python3
MacBook-Pro-2:~ admin$
add a comment |
It worked for me
sudo apt-get install python3-minimal
virtualenv --no-site-packages --distribute -p /usr/bin/python3 ~/.virtualenvs/py3
add a comment |
On windows:
py -3.4x32 -m venv venv34
or
py -2.6.2 -m venv venv26
This uses the py
launcher which will find the right python executable for you (assuming you have it installed).
add a comment |
virtualenv -p python3 myenv
Link to Creating virtualenv
add a comment |
For Debian (debian 9) Systems in 2019, I discovered a simple solution that may solve the problem from within the virtual environment.
Suppose the virtual environment were created via:
python3.7 -m venv myenv
but only has versions of python2
and python2.7
, and you need the recent features of python3.7.
Then, simply running the command:
(myvenv) $ python3.7 -m venv --upgrade /home/username/path/to/myvenv/
will add python3.7 packages if they are already available on your system.
add a comment |
This was a bug with virtualenv.
Just upgrading your pip should be the fix.
pip install --upgrade virtualenv
add a comment |
protected by Community♦ Jun 22 '14 at 19:41
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
21 Answers
21
active
oldest
votes
21 Answers
21
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
151
I figured I'd mention that this works for virtualenvwrappers too: mkvirtualenv -p python2.6 env
– bias
May 28 '10 at 3:24
53
I'm missing something here - doesn't this require that 2.6 already be installed on the system? I thought the point of virtualenv was that I could have a version of python other than the main one (in my case, 2.4 on CentOS). I was assuming I could install virtualenv, then install Python 2.6 under it for packages in the env to make use of?
– John C
May 24 '11 at 14:31
36
@John yes, you are. That isn't the point of virtualenv: the point of that is to create a sandboxed environment for Python. You will need to install that version first - you can install it locally for your user, though.
– Daniel Roseman
May 24 '11 at 14:47
8
@JohnC You can use pythonbrew to install alternative pythons.
– ashwoods
Dec 1 '11 at 22:03
44
If you are a tad lazy:virtualenv -p `which python2.6` <path/to/new/virtualenv>
– blaze
Oct 16 '13 at 0:57
|
show 10 more comments
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.
151
I figured I'd mention that this works for virtualenvwrappers too: mkvirtualenv -p python2.6 env
– bias
May 28 '10 at 3:24
53
I'm missing something here - doesn't this require that 2.6 already be installed on the system? I thought the point of virtualenv was that I could have a version of python other than the main one (in my case, 2.4 on CentOS). I was assuming I could install virtualenv, then install Python 2.6 under it for packages in the env to make use of?
– John C
May 24 '11 at 14:31
36
@John yes, you are. That isn't the point of virtualenv: the point of that is to create a sandboxed environment for Python. You will need to install that version first - you can install it locally for your user, though.
– Daniel Roseman
May 24 '11 at 14:47
8
@JohnC You can use pythonbrew to install alternative pythons.
– ashwoods
Dec 1 '11 at 22:03
44
If you are a tad lazy:virtualenv -p `which python2.6` <path/to/new/virtualenv>
– blaze
Oct 16 '13 at 0:57
|
show 10 more comments
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.
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.
edited Dec 4 '18 at 19:54
wjandrea
1,4861331
1,4861331
answered Oct 7 '09 at 21:33
Daniel RosemanDaniel Roseman
461k42598656
461k42598656
151
I figured I'd mention that this works for virtualenvwrappers too: mkvirtualenv -p python2.6 env
– bias
May 28 '10 at 3:24
53
I'm missing something here - doesn't this require that 2.6 already be installed on the system? I thought the point of virtualenv was that I could have a version of python other than the main one (in my case, 2.4 on CentOS). I was assuming I could install virtualenv, then install Python 2.6 under it for packages in the env to make use of?
– John C
May 24 '11 at 14:31
36
@John yes, you are. That isn't the point of virtualenv: the point of that is to create a sandboxed environment for Python. You will need to install that version first - you can install it locally for your user, though.
– Daniel Roseman
May 24 '11 at 14:47
8
@JohnC You can use pythonbrew to install alternative pythons.
– ashwoods
Dec 1 '11 at 22:03
44
If you are a tad lazy:virtualenv -p `which python2.6` <path/to/new/virtualenv>
– blaze
Oct 16 '13 at 0:57
|
show 10 more comments
151
I figured I'd mention that this works for virtualenvwrappers too: mkvirtualenv -p python2.6 env
– bias
May 28 '10 at 3:24
53
I'm missing something here - doesn't this require that 2.6 already be installed on the system? I thought the point of virtualenv was that I could have a version of python other than the main one (in my case, 2.4 on CentOS). I was assuming I could install virtualenv, then install Python 2.6 under it for packages in the env to make use of?
– John C
May 24 '11 at 14:31
36
@John yes, you are. That isn't the point of virtualenv: the point of that is to create a sandboxed environment for Python. You will need to install that version first - you can install it locally for your user, though.
– Daniel Roseman
May 24 '11 at 14:47
8
@JohnC You can use pythonbrew to install alternative pythons.
– ashwoods
Dec 1 '11 at 22:03
44
If you are a tad lazy:virtualenv -p `which python2.6` <path/to/new/virtualenv>
– blaze
Oct 16 '13 at 0:57
151
151
I figured I'd mention that this works for virtualenvwrappers too: mkvirtualenv -p python2.6 env
– bias
May 28 '10 at 3:24
I figured I'd mention that this works for virtualenvwrappers too: mkvirtualenv -p python2.6 env
– bias
May 28 '10 at 3:24
53
53
I'm missing something here - doesn't this require that 2.6 already be installed on the system? I thought the point of virtualenv was that I could have a version of python other than the main one (in my case, 2.4 on CentOS). I was assuming I could install virtualenv, then install Python 2.6 under it for packages in the env to make use of?
– John C
May 24 '11 at 14:31
I'm missing something here - doesn't this require that 2.6 already be installed on the system? I thought the point of virtualenv was that I could have a version of python other than the main one (in my case, 2.4 on CentOS). I was assuming I could install virtualenv, then install Python 2.6 under it for packages in the env to make use of?
– John C
May 24 '11 at 14:31
36
36
@John yes, you are. That isn't the point of virtualenv: the point of that is to create a sandboxed environment for Python. You will need to install that version first - you can install it locally for your user, though.
– Daniel Roseman
May 24 '11 at 14:47
@John yes, you are. That isn't the point of virtualenv: the point of that is to create a sandboxed environment for Python. You will need to install that version first - you can install it locally for your user, though.
– Daniel Roseman
May 24 '11 at 14:47
8
8
@JohnC You can use pythonbrew to install alternative pythons.
– ashwoods
Dec 1 '11 at 22:03
@JohnC You can use pythonbrew to install alternative pythons.
– ashwoods
Dec 1 '11 at 22:03
44
44
If you are a tad lazy:
virtualenv -p `which python2.6` <path/to/new/virtualenv>
– blaze
Oct 16 '13 at 0:57
If you are a tad lazy:
virtualenv -p `which python2.6` <path/to/new/virtualenv>
– blaze
Oct 16 '13 at 0:57
|
show 10 more comments
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.
5
Glad you pointed that out, it needs more promotion. One minor nit: they are now advocating running it aspython3 -m venv <envname>
to prevent needing stub scripts for everything.
– Paul Everitt
Nov 20 '16 at 16:08
5
In fact thepyvenv
script is deprecated in Python 3.6+, though the underlyingvenv
module itself is not. So usepython 3 -m venv <myenvname>
as @PaulEveritt says.
– RichVel
Dec 20 '16 at 8:47
3
Be warned thatpyvenv
orpython3 -m venv ...
do NOT install thepython-config
script. This means that even after activating your Python3 environment the system-widepython-config
will be invoked with confusing consequences. See this bug report from 2011 github.com/pypa/virtualenv/issues/169 and my question stackoverflow.com/questions/42020937/…
– Laryx Decidua
Feb 23 '18 at 11:16
add a comment |
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.
5
Glad you pointed that out, it needs more promotion. One minor nit: they are now advocating running it aspython3 -m venv <envname>
to prevent needing stub scripts for everything.
– Paul Everitt
Nov 20 '16 at 16:08
5
In fact thepyvenv
script is deprecated in Python 3.6+, though the underlyingvenv
module itself is not. So usepython 3 -m venv <myenvname>
as @PaulEveritt says.
– RichVel
Dec 20 '16 at 8:47
3
Be warned thatpyvenv
orpython3 -m venv ...
do NOT install thepython-config
script. This means that even after activating your Python3 environment the system-widepython-config
will be invoked with confusing consequences. See this bug report from 2011 github.com/pypa/virtualenv/issues/169 and my question stackoverflow.com/questions/42020937/…
– Laryx Decidua
Feb 23 '18 at 11:16
add a comment |
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.
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.
edited Apr 2 '18 at 21:56
mc_kaiser
443515
443515
answered Sep 26 '16 at 22:46
The AelfinnThe Aelfinn
4,61912329
4,61912329
5
Glad you pointed that out, it needs more promotion. One minor nit: they are now advocating running it aspython3 -m venv <envname>
to prevent needing stub scripts for everything.
– Paul Everitt
Nov 20 '16 at 16:08
5
In fact thepyvenv
script is deprecated in Python 3.6+, though the underlyingvenv
module itself is not. So usepython 3 -m venv <myenvname>
as @PaulEveritt says.
– RichVel
Dec 20 '16 at 8:47
3
Be warned thatpyvenv
orpython3 -m venv ...
do NOT install thepython-config
script. This means that even after activating your Python3 environment the system-widepython-config
will be invoked with confusing consequences. See this bug report from 2011 github.com/pypa/virtualenv/issues/169 and my question stackoverflow.com/questions/42020937/…
– Laryx Decidua
Feb 23 '18 at 11:16
add a comment |
5
Glad you pointed that out, it needs more promotion. One minor nit: they are now advocating running it aspython3 -m venv <envname>
to prevent needing stub scripts for everything.
– Paul Everitt
Nov 20 '16 at 16:08
5
In fact thepyvenv
script is deprecated in Python 3.6+, though the underlyingvenv
module itself is not. So usepython 3 -m venv <myenvname>
as @PaulEveritt says.
– RichVel
Dec 20 '16 at 8:47
3
Be warned thatpyvenv
orpython3 -m venv ...
do NOT install thepython-config
script. This means that even after activating your Python3 environment the system-widepython-config
will be invoked with confusing consequences. See this bug report from 2011 github.com/pypa/virtualenv/issues/169 and my question stackoverflow.com/questions/42020937/…
– Laryx Decidua
Feb 23 '18 at 11:16
5
5
Glad you pointed that out, it needs more promotion. One minor nit: they are now advocating running it as
python3 -m venv <envname>
to prevent needing stub scripts for everything.– Paul Everitt
Nov 20 '16 at 16:08
Glad you pointed that out, it needs more promotion. One minor nit: they are now advocating running it as
python3 -m venv <envname>
to prevent needing stub scripts for everything.– Paul Everitt
Nov 20 '16 at 16:08
5
5
In fact the
pyvenv
script is deprecated in Python 3.6+, though the underlying venv
module itself is not. So use python 3 -m venv <myenvname>
as @PaulEveritt says.– RichVel
Dec 20 '16 at 8:47
In fact the
pyvenv
script is deprecated in Python 3.6+, though the underlying venv
module itself is not. So use python 3 -m venv <myenvname>
as @PaulEveritt says.– RichVel
Dec 20 '16 at 8:47
3
3
Be warned that
pyvenv
or python3 -m venv ...
do NOT install the python-config
script. This means that even after activating your Python3 environment the system-wide python-config
will be invoked with confusing consequences. See this bug report from 2011 github.com/pypa/virtualenv/issues/169 and my question stackoverflow.com/questions/42020937/…– Laryx Decidua
Feb 23 '18 at 11:16
Be warned that
pyvenv
or python3 -m venv ...
do NOT install the python-config
script. This means that even after activating your Python3 environment the system-wide python-config
will be invoked with confusing consequences. See this bug report from 2011 github.com/pypa/virtualenv/issues/169 and my question stackoverflow.com/questions/42020937/…– Laryx Decidua
Feb 23 '18 at 11:16
add a comment |
These are steps when you are on shared hosting environment and need to install & complie 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.
2
Could you elaborate on why to do it that way: Why install python locally? And more importantly why install virtualenv using the python version you want to use with it?
– lajarre
Oct 8 '12 at 19:46
14
sure. If you are on virtual hosting environment and the server provides older versions of python that you are not happy with - that was my case scenario. Also if you happen to develop projects on different servers and you want to replicate these environments on your local machine.... Virtualenv creates hard links to python libs . so it's really important with version of python you are using to install and create Virtualenv from.
– zzart
Oct 11 '12 at 20:15
6
Or if you are like me and am on a locked down machine at work with no sudo privileges. Local copies of libraries, SQL databases, languages and compilers galore! Thanks!
– zachd1_618
Jan 24 '13 at 18:03
4
Under virtualenv 1.9.1, I had to use~/.localpython/bin/virtualenv
instead of justvirtualenv
for setup to complete without errors. In addition, usesource ve/bin/activate
instead ofsource activate
.
– Saul
Apr 10 '13 at 7:40
3
Another reason to do this would be to try out betas before they go main to make sure your projects and their dependencies still work without risking breaking your package management by clobbering something and leaving dangling files all over the place. I like this answer.
– RobotHumans
Dec 29 '13 at 14:02
|
show 4 more comments
These are steps when you are on shared hosting environment and need to install & complie 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.
2
Could you elaborate on why to do it that way: Why install python locally? And more importantly why install virtualenv using the python version you want to use with it?
– lajarre
Oct 8 '12 at 19:46
14
sure. If you are on virtual hosting environment and the server provides older versions of python that you are not happy with - that was my case scenario. Also if you happen to develop projects on different servers and you want to replicate these environments on your local machine.... Virtualenv creates hard links to python libs . so it's really important with version of python you are using to install and create Virtualenv from.
– zzart
Oct 11 '12 at 20:15
6
Or if you are like me and am on a locked down machine at work with no sudo privileges. Local copies of libraries, SQL databases, languages and compilers galore! Thanks!
– zachd1_618
Jan 24 '13 at 18:03
4
Under virtualenv 1.9.1, I had to use~/.localpython/bin/virtualenv
instead of justvirtualenv
for setup to complete without errors. In addition, usesource ve/bin/activate
instead ofsource activate
.
– Saul
Apr 10 '13 at 7:40
3
Another reason to do this would be to try out betas before they go main to make sure your projects and their dependencies still work without risking breaking your package management by clobbering something and leaving dangling files all over the place. I like this answer.
– RobotHumans
Dec 29 '13 at 14:02
|
show 4 more comments
These are steps when you are on shared hosting environment and need to install & complie 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.
These are steps when you are on shared hosting environment and need to install & complie 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.
edited Jul 1 '16 at 10:25
Ivan Klass
4,75022024
4,75022024
answered Jul 2 '12 at 22:17
zzartzzart
7,60443843
7,60443843
2
Could you elaborate on why to do it that way: Why install python locally? And more importantly why install virtualenv using the python version you want to use with it?
– lajarre
Oct 8 '12 at 19:46
14
sure. If you are on virtual hosting environment and the server provides older versions of python that you are not happy with - that was my case scenario. Also if you happen to develop projects on different servers and you want to replicate these environments on your local machine.... Virtualenv creates hard links to python libs . so it's really important with version of python you are using to install and create Virtualenv from.
– zzart
Oct 11 '12 at 20:15
6
Or if you are like me and am on a locked down machine at work with no sudo privileges. Local copies of libraries, SQL databases, languages and compilers galore! Thanks!
– zachd1_618
Jan 24 '13 at 18:03
4
Under virtualenv 1.9.1, I had to use~/.localpython/bin/virtualenv
instead of justvirtualenv
for setup to complete without errors. In addition, usesource ve/bin/activate
instead ofsource activate
.
– Saul
Apr 10 '13 at 7:40
3
Another reason to do this would be to try out betas before they go main to make sure your projects and their dependencies still work without risking breaking your package management by clobbering something and leaving dangling files all over the place. I like this answer.
– RobotHumans
Dec 29 '13 at 14:02
|
show 4 more comments
2
Could you elaborate on why to do it that way: Why install python locally? And more importantly why install virtualenv using the python version you want to use with it?
– lajarre
Oct 8 '12 at 19:46
14
sure. If you are on virtual hosting environment and the server provides older versions of python that you are not happy with - that was my case scenario. Also if you happen to develop projects on different servers and you want to replicate these environments on your local machine.... Virtualenv creates hard links to python libs . so it's really important with version of python you are using to install and create Virtualenv from.
– zzart
Oct 11 '12 at 20:15
6
Or if you are like me and am on a locked down machine at work with no sudo privileges. Local copies of libraries, SQL databases, languages and compilers galore! Thanks!
– zachd1_618
Jan 24 '13 at 18:03
4
Under virtualenv 1.9.1, I had to use~/.localpython/bin/virtualenv
instead of justvirtualenv
for setup to complete without errors. In addition, usesource ve/bin/activate
instead ofsource activate
.
– Saul
Apr 10 '13 at 7:40
3
Another reason to do this would be to try out betas before they go main to make sure your projects and their dependencies still work without risking breaking your package management by clobbering something and leaving dangling files all over the place. I like this answer.
– RobotHumans
Dec 29 '13 at 14:02
2
2
Could you elaborate on why to do it that way: Why install python locally? And more importantly why install virtualenv using the python version you want to use with it?
– lajarre
Oct 8 '12 at 19:46
Could you elaborate on why to do it that way: Why install python locally? And more importantly why install virtualenv using the python version you want to use with it?
– lajarre
Oct 8 '12 at 19:46
14
14
sure. If you are on virtual hosting environment and the server provides older versions of python that you are not happy with - that was my case scenario. Also if you happen to develop projects on different servers and you want to replicate these environments on your local machine.... Virtualenv creates hard links to python libs . so it's really important with version of python you are using to install and create Virtualenv from.
– zzart
Oct 11 '12 at 20:15
sure. If you are on virtual hosting environment and the server provides older versions of python that you are not happy with - that was my case scenario. Also if you happen to develop projects on different servers and you want to replicate these environments on your local machine.... Virtualenv creates hard links to python libs . so it's really important with version of python you are using to install and create Virtualenv from.
– zzart
Oct 11 '12 at 20:15
6
6
Or if you are like me and am on a locked down machine at work with no sudo privileges. Local copies of libraries, SQL databases, languages and compilers galore! Thanks!
– zachd1_618
Jan 24 '13 at 18:03
Or if you are like me and am on a locked down machine at work with no sudo privileges. Local copies of libraries, SQL databases, languages and compilers galore! Thanks!
– zachd1_618
Jan 24 '13 at 18:03
4
4
Under virtualenv 1.9.1, I had to use
~/.localpython/bin/virtualenv
instead of just virtualenv
for setup to complete without errors. In addition, use source ve/bin/activate
instead of source activate
.– Saul
Apr 10 '13 at 7:40
Under virtualenv 1.9.1, I had to use
~/.localpython/bin/virtualenv
instead of just virtualenv
for setup to complete without errors. In addition, use source ve/bin/activate
instead of source activate
.– Saul
Apr 10 '13 at 7:40
3
3
Another reason to do this would be to try out betas before they go main to make sure your projects and their dependencies still work without risking breaking your package management by clobbering something and leaving dangling files all over the place. I like this answer.
– RobotHumans
Dec 29 '13 at 14:02
Another reason to do this would be to try out betas before they go main to make sure your projects and their dependencies still work without risking breaking your package management by clobbering something and leaving dangling files all over the place. I like this answer.
– RobotHumans
Dec 29 '13 at 14:02
|
show 4 more comments
virtualenv --python=/usr/bin/python2.6 <path/to/myvirtualenv>
2
See my answer below for an equivalent solution using environment variables. That approach means you don't have to remember to use-p
.
– Chris Johnson
Aug 5 '16 at 20:58
5
Is there no solutions that switches between python versions without requiring to create a new virtual environment?
– Charlie Parker
Aug 28 '16 at 22:27
Would this work, if you want to install a python version that is not installed on your system? Say you want to test outpython3.6
but dont want to touchpython3.5
installed on your computer?
– alpha_989
Jul 31 '18 at 3:53
add a comment |
virtualenv --python=/usr/bin/python2.6 <path/to/myvirtualenv>
2
See my answer below for an equivalent solution using environment variables. That approach means you don't have to remember to use-p
.
– Chris Johnson
Aug 5 '16 at 20:58
5
Is there no solutions that switches between python versions without requiring to create a new virtual environment?
– Charlie Parker
Aug 28 '16 at 22:27
Would this work, if you want to install a python version that is not installed on your system? Say you want to test outpython3.6
but dont want to touchpython3.5
installed on your computer?
– alpha_989
Jul 31 '18 at 3:53
add a comment |
virtualenv --python=/usr/bin/python2.6 <path/to/myvirtualenv>
virtualenv --python=/usr/bin/python2.6 <path/to/myvirtualenv>
edited Oct 8 '14 at 23:53
Jan
1,04621219
1,04621219
answered Nov 4 '09 at 15:15
iElectriciElectric
4,5441924
4,5441924
2
See my answer below for an equivalent solution using environment variables. That approach means you don't have to remember to use-p
.
– Chris Johnson
Aug 5 '16 at 20:58
5
Is there no solutions that switches between python versions without requiring to create a new virtual environment?
– Charlie Parker
Aug 28 '16 at 22:27
Would this work, if you want to install a python version that is not installed on your system? Say you want to test outpython3.6
but dont want to touchpython3.5
installed on your computer?
– alpha_989
Jul 31 '18 at 3:53
add a comment |
2
See my answer below for an equivalent solution using environment variables. That approach means you don't have to remember to use-p
.
– Chris Johnson
Aug 5 '16 at 20:58
5
Is there no solutions that switches between python versions without requiring to create a new virtual environment?
– Charlie Parker
Aug 28 '16 at 22:27
Would this work, if you want to install a python version that is not installed on your system? Say you want to test outpython3.6
but dont want to touchpython3.5
installed on your computer?
– alpha_989
Jul 31 '18 at 3:53
2
2
See my answer below for an equivalent solution using environment variables. That approach means you don't have to remember to use
-p
.– Chris Johnson
Aug 5 '16 at 20:58
See my answer below for an equivalent solution using environment variables. That approach means you don't have to remember to use
-p
.– Chris Johnson
Aug 5 '16 at 20:58
5
5
Is there no solutions that switches between python versions without requiring to create a new virtual environment?
– Charlie Parker
Aug 28 '16 at 22:27
Is there no solutions that switches between python versions without requiring to create a new virtual environment?
– Charlie Parker
Aug 28 '16 at 22:27
Would this work, if you want to install a python version that is not installed on your system? Say you want to test out
python3.6
but dont want to touch python3.5
installed on your computer?– alpha_989
Jul 31 '18 at 3:53
Would this work, if you want to install a python version that is not installed on your system? Say you want to test out
python3.6
but dont want to touch python3.5
installed on your computer?– alpha_989
Jul 31 '18 at 3:53
add a comment |
There is an easier way,
virtualenv venv --python=python2.7
Thanks to a comment, this only works if you have python2.7 installed at the system level (e.g. /usr/bin/python2.7).
Otherwise, if you are using homebrew you can use the path to give you what you want.
virtualenv venv --python=/usr/local/bin/python
You can find the path to your python installation with
which python
This will also work with python 3.
which python3
>> /usr/local/bin/python3
virtualenv venv --python=/usr/local/bin/python3
Ultimately condensing to:
virtualenv venv -p `which python`
virtualenv venv -p `which python3`
1
FYI, only works if you have python2.7 installed at the system level (e.g. /usr/bin/python2.7)
– kingb12
Jan 27 '17 at 20:23
I was able to do this withvirtualenv venv --python=python3.6
as well
– Jordan
Sep 7 '17 at 18:03
You can actually drop the minor version number.virtualenv env --python=python2
– Anshul
Feb 5 '18 at 6:56
That's a proper solution, once you have all versions, you are interested in justing using the alias not the full path
– user1767754
Nov 20 '18 at 19:54
add a comment |
There is an easier way,
virtualenv venv --python=python2.7
Thanks to a comment, this only works if you have python2.7 installed at the system level (e.g. /usr/bin/python2.7).
Otherwise, if you are using homebrew you can use the path to give you what you want.
virtualenv venv --python=/usr/local/bin/python
You can find the path to your python installation with
which python
This will also work with python 3.
which python3
>> /usr/local/bin/python3
virtualenv venv --python=/usr/local/bin/python3
Ultimately condensing to:
virtualenv venv -p `which python`
virtualenv venv -p `which python3`
1
FYI, only works if you have python2.7 installed at the system level (e.g. /usr/bin/python2.7)
– kingb12
Jan 27 '17 at 20:23
I was able to do this withvirtualenv venv --python=python3.6
as well
– Jordan
Sep 7 '17 at 18:03
You can actually drop the minor version number.virtualenv env --python=python2
– Anshul
Feb 5 '18 at 6:56
That's a proper solution, once you have all versions, you are interested in justing using the alias not the full path
– user1767754
Nov 20 '18 at 19:54
add a comment |
There is an easier way,
virtualenv venv --python=python2.7
Thanks to a comment, this only works if you have python2.7 installed at the system level (e.g. /usr/bin/python2.7).
Otherwise, if you are using homebrew you can use the path to give you what you want.
virtualenv venv --python=/usr/local/bin/python
You can find the path to your python installation with
which python
This will also work with python 3.
which python3
>> /usr/local/bin/python3
virtualenv venv --python=/usr/local/bin/python3
Ultimately condensing to:
virtualenv venv -p `which python`
virtualenv venv -p `which python3`
There is an easier way,
virtualenv venv --python=python2.7
Thanks to a comment, this only works if you have python2.7 installed at the system level (e.g. /usr/bin/python2.7).
Otherwise, if you are using homebrew you can use the path to give you what you want.
virtualenv venv --python=/usr/local/bin/python
You can find the path to your python installation with
which python
This will also work with python 3.
which python3
>> /usr/local/bin/python3
virtualenv venv --python=/usr/local/bin/python3
Ultimately condensing to:
virtualenv venv -p `which python`
virtualenv venv -p `which python3`
edited May 24 '17 at 7:28
answered Nov 1 '16 at 11:59
Daniel LeeDaniel Lee
2,67711325
2,67711325
1
FYI, only works if you have python2.7 installed at the system level (e.g. /usr/bin/python2.7)
– kingb12
Jan 27 '17 at 20:23
I was able to do this withvirtualenv venv --python=python3.6
as well
– Jordan
Sep 7 '17 at 18:03
You can actually drop the minor version number.virtualenv env --python=python2
– Anshul
Feb 5 '18 at 6:56
That's a proper solution, once you have all versions, you are interested in justing using the alias not the full path
– user1767754
Nov 20 '18 at 19:54
add a comment |
1
FYI, only works if you have python2.7 installed at the system level (e.g. /usr/bin/python2.7)
– kingb12
Jan 27 '17 at 20:23
I was able to do this withvirtualenv venv --python=python3.6
as well
– Jordan
Sep 7 '17 at 18:03
You can actually drop the minor version number.virtualenv env --python=python2
– Anshul
Feb 5 '18 at 6:56
That's a proper solution, once you have all versions, you are interested in justing using the alias not the full path
– user1767754
Nov 20 '18 at 19:54
1
1
FYI, only works if you have python2.7 installed at the system level (e.g. /usr/bin/python2.7)
– kingb12
Jan 27 '17 at 20:23
FYI, only works if you have python2.7 installed at the system level (e.g. /usr/bin/python2.7)
– kingb12
Jan 27 '17 at 20:23
I was able to do this with
virtualenv venv --python=python3.6
as well– Jordan
Sep 7 '17 at 18:03
I was able to do this with
virtualenv venv --python=python3.6
as well– Jordan
Sep 7 '17 at 18:03
You can actually drop the minor version number.
virtualenv env --python=python2
– Anshul
Feb 5 '18 at 6:56
You can actually drop the minor version number.
virtualenv env --python=python2
– Anshul
Feb 5 '18 at 6:56
That's a proper solution, once you have all versions, you are interested in justing using the alias not the full path
– user1767754
Nov 20 '18 at 19:54
That's a proper solution, once you have all versions, you are interested in justing using the alias not the full path
– user1767754
Nov 20 '18 at 19:54
add a comment |
Under Windows for me this works:
virtualenv --python=c:Python25python.exe envname
without the python.exe
I got WindowsError: [Error 5] Access is denied
I have Python2.7.1 installed with virtualenv 1.6.1, and I wanted python 2.5.2.
add a comment |
Under Windows for me this works:
virtualenv --python=c:Python25python.exe envname
without the python.exe
I got WindowsError: [Error 5] Access is denied
I have Python2.7.1 installed with virtualenv 1.6.1, and I wanted python 2.5.2.
add a comment |
Under Windows for me this works:
virtualenv --python=c:Python25python.exe envname
without the python.exe
I got WindowsError: [Error 5] Access is denied
I have Python2.7.1 installed with virtualenv 1.6.1, and I wanted python 2.5.2.
Under Windows for me this works:
virtualenv --python=c:Python25python.exe envname
without the python.exe
I got WindowsError: [Error 5] Access is denied
I have Python2.7.1 installed with virtualenv 1.6.1, and I wanted python 2.5.2.
answered Jul 31 '11 at 21:04
balazsbalazs
4,17852943
4,17852943
add a comment |
add a comment |
Mac OSX 10.6.8 (Snow Leopard):
1) When you do pip install virtualenv
, the pip command is associated with one of your python versions, and virtualenv
gets installed into that version of python. You can do
$ which pip
to see what version of python that is. If you see something like:
$ which pip
/usr/local/bin/pip
then do:
$ ls -al /usr/local/bin/pip
lrwxrwxr-x 1 root admin 65 Apr 10 2015 /usr/local/bin/pip ->
../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pip
You can see the python version in the output.
By default, that will be the version of python that is used for any new environment you create. However, you can specify any version of python installed on your computer to use inside a new environment with the -p flag
:
$ virtualenv -p python3.2 my_env
Running virtualenv with interpreter /usr/local/bin/python3.2
New python executable in my_env/bin/python
Installing setuptools, pip...done.
virtualenv my_env
will create a folder in the current directory which
will contain the Python executable files, and a copy of the pip
[command] which you can use to install other packages.
http://docs.python-guide.org/en/latest/dev/virtualenvs/
virtualenv
just copies python from a location on your computer into the newly created my_env/bin/ directory.
2) The system python is in /usr/bin
, while the various python versions I installed were, by default, installed into:
/usr/local/bin
3) The various pythons I installed have names like python2.7
or python3.2
, and I can use those names rather than full paths.
========VIRTUALENVWRAPPER=========
1) I had some problems getting virtualenvwrapper to work. This is what I ended up putting in ~/.bash_profile
:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/django_projects #Not very important -- mkproject command uses this
#Added the following based on:
#http://stackoverflow.com/questions/19665327/virtualenvwrapper-installation-snow-leopard-python
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python2.7
#source /usr/local/bin/virtualenvwrapper.sh
source /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh
2) The -p option
works differently with virtualenvwrapper: I have to specify the full path to the python interpreter to be used in the new environment(when I do not want to use the default python version):
$ mkvirtualenv -p /usr/local/bin/python3.2 my_env
Running virtualenv with interpreter /usr/local/bin/python3
New python executable in my_env/bin/python
Installing setuptools, pip...done.
Usage: source deactivate
removes the 'bin' directory of the environment activated with 'source
activate' from PATH.
Unlike virtualenv, virtualenvwrapper will create the environment at the location specified by the $WORKON_HOME environment variable. That keeps all your environments in one place.
which pip
doesn't tell me the version of Python. It gives me this-/usr/local/bin/pip
.
– Sankalp
Mar 16 '18 at 2:36
@Sankalp, If you cd to/usr/local/bin
and do$ ls -al pip
, you should see something like:pip -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pip
– 7stud
Mar 16 '18 at 2:44
Already somewhat noted in answer, butmkproject
is the command to use if you want it to create both the project directory and a virtual environment of a given python version.mkproject -p /usr/bin/python3.6 myNewPython36Project
– Jim Factor
Jan 24 at 5:13
add a comment |
Mac OSX 10.6.8 (Snow Leopard):
1) When you do pip install virtualenv
, the pip command is associated with one of your python versions, and virtualenv
gets installed into that version of python. You can do
$ which pip
to see what version of python that is. If you see something like:
$ which pip
/usr/local/bin/pip
then do:
$ ls -al /usr/local/bin/pip
lrwxrwxr-x 1 root admin 65 Apr 10 2015 /usr/local/bin/pip ->
../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pip
You can see the python version in the output.
By default, that will be the version of python that is used for any new environment you create. However, you can specify any version of python installed on your computer to use inside a new environment with the -p flag
:
$ virtualenv -p python3.2 my_env
Running virtualenv with interpreter /usr/local/bin/python3.2
New python executable in my_env/bin/python
Installing setuptools, pip...done.
virtualenv my_env
will create a folder in the current directory which
will contain the Python executable files, and a copy of the pip
[command] which you can use to install other packages.
http://docs.python-guide.org/en/latest/dev/virtualenvs/
virtualenv
just copies python from a location on your computer into the newly created my_env/bin/ directory.
2) The system python is in /usr/bin
, while the various python versions I installed were, by default, installed into:
/usr/local/bin
3) The various pythons I installed have names like python2.7
or python3.2
, and I can use those names rather than full paths.
========VIRTUALENVWRAPPER=========
1) I had some problems getting virtualenvwrapper to work. This is what I ended up putting in ~/.bash_profile
:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/django_projects #Not very important -- mkproject command uses this
#Added the following based on:
#http://stackoverflow.com/questions/19665327/virtualenvwrapper-installation-snow-leopard-python
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python2.7
#source /usr/local/bin/virtualenvwrapper.sh
source /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh
2) The -p option
works differently with virtualenvwrapper: I have to specify the full path to the python interpreter to be used in the new environment(when I do not want to use the default python version):
$ mkvirtualenv -p /usr/local/bin/python3.2 my_env
Running virtualenv with interpreter /usr/local/bin/python3
New python executable in my_env/bin/python
Installing setuptools, pip...done.
Usage: source deactivate
removes the 'bin' directory of the environment activated with 'source
activate' from PATH.
Unlike virtualenv, virtualenvwrapper will create the environment at the location specified by the $WORKON_HOME environment variable. That keeps all your environments in one place.
which pip
doesn't tell me the version of Python. It gives me this-/usr/local/bin/pip
.
– Sankalp
Mar 16 '18 at 2:36
@Sankalp, If you cd to/usr/local/bin
and do$ ls -al pip
, you should see something like:pip -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pip
– 7stud
Mar 16 '18 at 2:44
Already somewhat noted in answer, butmkproject
is the command to use if you want it to create both the project directory and a virtual environment of a given python version.mkproject -p /usr/bin/python3.6 myNewPython36Project
– Jim Factor
Jan 24 at 5:13
add a comment |
Mac OSX 10.6.8 (Snow Leopard):
1) When you do pip install virtualenv
, the pip command is associated with one of your python versions, and virtualenv
gets installed into that version of python. You can do
$ which pip
to see what version of python that is. If you see something like:
$ which pip
/usr/local/bin/pip
then do:
$ ls -al /usr/local/bin/pip
lrwxrwxr-x 1 root admin 65 Apr 10 2015 /usr/local/bin/pip ->
../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pip
You can see the python version in the output.
By default, that will be the version of python that is used for any new environment you create. However, you can specify any version of python installed on your computer to use inside a new environment with the -p flag
:
$ virtualenv -p python3.2 my_env
Running virtualenv with interpreter /usr/local/bin/python3.2
New python executable in my_env/bin/python
Installing setuptools, pip...done.
virtualenv my_env
will create a folder in the current directory which
will contain the Python executable files, and a copy of the pip
[command] which you can use to install other packages.
http://docs.python-guide.org/en/latest/dev/virtualenvs/
virtualenv
just copies python from a location on your computer into the newly created my_env/bin/ directory.
2) The system python is in /usr/bin
, while the various python versions I installed were, by default, installed into:
/usr/local/bin
3) The various pythons I installed have names like python2.7
or python3.2
, and I can use those names rather than full paths.
========VIRTUALENVWRAPPER=========
1) I had some problems getting virtualenvwrapper to work. This is what I ended up putting in ~/.bash_profile
:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/django_projects #Not very important -- mkproject command uses this
#Added the following based on:
#http://stackoverflow.com/questions/19665327/virtualenvwrapper-installation-snow-leopard-python
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python2.7
#source /usr/local/bin/virtualenvwrapper.sh
source /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh
2) The -p option
works differently with virtualenvwrapper: I have to specify the full path to the python interpreter to be used in the new environment(when I do not want to use the default python version):
$ mkvirtualenv -p /usr/local/bin/python3.2 my_env
Running virtualenv with interpreter /usr/local/bin/python3
New python executable in my_env/bin/python
Installing setuptools, pip...done.
Usage: source deactivate
removes the 'bin' directory of the environment activated with 'source
activate' from PATH.
Unlike virtualenv, virtualenvwrapper will create the environment at the location specified by the $WORKON_HOME environment variable. That keeps all your environments in one place.
Mac OSX 10.6.8 (Snow Leopard):
1) When you do pip install virtualenv
, the pip command is associated with one of your python versions, and virtualenv
gets installed into that version of python. You can do
$ which pip
to see what version of python that is. If you see something like:
$ which pip
/usr/local/bin/pip
then do:
$ ls -al /usr/local/bin/pip
lrwxrwxr-x 1 root admin 65 Apr 10 2015 /usr/local/bin/pip ->
../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pip
You can see the python version in the output.
By default, that will be the version of python that is used for any new environment you create. However, you can specify any version of python installed on your computer to use inside a new environment with the -p flag
:
$ virtualenv -p python3.2 my_env
Running virtualenv with interpreter /usr/local/bin/python3.2
New python executable in my_env/bin/python
Installing setuptools, pip...done.
virtualenv my_env
will create a folder in the current directory which
will contain the Python executable files, and a copy of the pip
[command] which you can use to install other packages.
http://docs.python-guide.org/en/latest/dev/virtualenvs/
virtualenv
just copies python from a location on your computer into the newly created my_env/bin/ directory.
2) The system python is in /usr/bin
, while the various python versions I installed were, by default, installed into:
/usr/local/bin
3) The various pythons I installed have names like python2.7
or python3.2
, and I can use those names rather than full paths.
========VIRTUALENVWRAPPER=========
1) I had some problems getting virtualenvwrapper to work. This is what I ended up putting in ~/.bash_profile
:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/django_projects #Not very important -- mkproject command uses this
#Added the following based on:
#http://stackoverflow.com/questions/19665327/virtualenvwrapper-installation-snow-leopard-python
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python2.7
#source /usr/local/bin/virtualenvwrapper.sh
source /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh
2) The -p option
works differently with virtualenvwrapper: I have to specify the full path to the python interpreter to be used in the new environment(when I do not want to use the default python version):
$ mkvirtualenv -p /usr/local/bin/python3.2 my_env
Running virtualenv with interpreter /usr/local/bin/python3
New python executable in my_env/bin/python
Installing setuptools, pip...done.
Usage: source deactivate
removes the 'bin' directory of the environment activated with 'source
activate' from PATH.
Unlike virtualenv, virtualenvwrapper will create the environment at the location specified by the $WORKON_HOME environment variable. That keeps all your environments in one place.
edited Mar 16 '18 at 2:49
answered Jan 15 '15 at 20:43
7stud7stud
30.6k96687
30.6k96687
which pip
doesn't tell me the version of Python. It gives me this-/usr/local/bin/pip
.
– Sankalp
Mar 16 '18 at 2:36
@Sankalp, If you cd to/usr/local/bin
and do$ ls -al pip
, you should see something like:pip -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pip
– 7stud
Mar 16 '18 at 2:44
Already somewhat noted in answer, butmkproject
is the command to use if you want it to create both the project directory and a virtual environment of a given python version.mkproject -p /usr/bin/python3.6 myNewPython36Project
– Jim Factor
Jan 24 at 5:13
add a comment |
which pip
doesn't tell me the version of Python. It gives me this-/usr/local/bin/pip
.
– Sankalp
Mar 16 '18 at 2:36
@Sankalp, If you cd to/usr/local/bin
and do$ ls -al pip
, you should see something like:pip -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pip
– 7stud
Mar 16 '18 at 2:44
Already somewhat noted in answer, butmkproject
is the command to use if you want it to create both the project directory and a virtual environment of a given python version.mkproject -p /usr/bin/python3.6 myNewPython36Project
– Jim Factor
Jan 24 at 5:13
which pip
doesn't tell me the version of Python. It gives me this- /usr/local/bin/pip
.– Sankalp
Mar 16 '18 at 2:36
which pip
doesn't tell me the version of Python. It gives me this- /usr/local/bin/pip
.– Sankalp
Mar 16 '18 at 2:36
@Sankalp, If you cd to
/usr/local/bin
and do $ ls -al pip
, you should see something like: pip -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pip
– 7stud
Mar 16 '18 at 2:44
@Sankalp, If you cd to
/usr/local/bin
and do $ ls -al pip
, you should see something like: pip -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pip
– 7stud
Mar 16 '18 at 2:44
Already somewhat noted in answer, but
mkproject
is the command to use if you want it to create both the project directory and a virtual environment of a given python version. mkproject -p /usr/bin/python3.6 myNewPython36Project
– Jim Factor
Jan 24 at 5:13
Already somewhat noted in answer, but
mkproject
is the command to use if you want it to create both the project directory and a virtual environment of a given python version. mkproject -p /usr/bin/python3.6 myNewPython36Project
– Jim Factor
Jan 24 at 5:13
add a comment |
Suppose you currently have python 2.7 installed in your virtualenv. But want to make use of python3.2
, You would have to update this with:
$ virtualenv --python=/usr/bin/python3.2 name_of_your_virtualenv
Then activate your virtualenv by:
$ source activate name_of_your_virtualenv
and then do: python --version
in shell to check whether your version is now updated.
See my answer below for an equivalent solution using environment variables. That approach means you don't have to remember to use-p
.
– Chris Johnson
Aug 5 '16 at 20:58
add a comment |
Suppose you currently have python 2.7 installed in your virtualenv. But want to make use of python3.2
, You would have to update this with:
$ virtualenv --python=/usr/bin/python3.2 name_of_your_virtualenv
Then activate your virtualenv by:
$ source activate name_of_your_virtualenv
and then do: python --version
in shell to check whether your version is now updated.
See my answer below for an equivalent solution using environment variables. That approach means you don't have to remember to use-p
.
– Chris Johnson
Aug 5 '16 at 20:58
add a comment |
Suppose you currently have python 2.7 installed in your virtualenv. But want to make use of python3.2
, You would have to update this with:
$ virtualenv --python=/usr/bin/python3.2 name_of_your_virtualenv
Then activate your virtualenv by:
$ source activate name_of_your_virtualenv
and then do: python --version
in shell to check whether your version is now updated.
Suppose you currently have python 2.7 installed in your virtualenv. But want to make use of python3.2
, You would have to update this with:
$ virtualenv --python=/usr/bin/python3.2 name_of_your_virtualenv
Then activate your virtualenv by:
$ source activate name_of_your_virtualenv
and then do: python --version
in shell to check whether your version is now updated.
edited Sep 8 '18 at 18:29
answered Dec 30 '13 at 5:51
kmario23kmario23
19.4k46480
19.4k46480
See my answer below for an equivalent solution using environment variables. That approach means you don't have to remember to use-p
.
– Chris Johnson
Aug 5 '16 at 20:58
add a comment |
See my answer below for an equivalent solution using environment variables. That approach means you don't have to remember to use-p
.
– Chris Johnson
Aug 5 '16 at 20:58
See my answer below for an equivalent solution using environment variables. That approach means you don't have to remember to use
-p
.– Chris Johnson
Aug 5 '16 at 20:58
See my answer below for an equivalent solution using environment variables. That approach means you don't have to remember to use
-p
.– Chris Johnson
Aug 5 '16 at 20:58
add a comment |
These two commands should work fine for a newbie
virtualenv -p python2 myenv
(For python2)
virtualenv -p python3 myenv
(For python3)
1
The flag -p python2 works equivalent to looking for /usr/bin/python2. Use : virtualenv -p python2.7 myenv for 2.7 etc.
– Yash Sharma
Dec 28 '18 at 2:05
add a comment |
These two commands should work fine for a newbie
virtualenv -p python2 myenv
(For python2)
virtualenv -p python3 myenv
(For python3)
1
The flag -p python2 works equivalent to looking for /usr/bin/python2. Use : virtualenv -p python2.7 myenv for 2.7 etc.
– Yash Sharma
Dec 28 '18 at 2:05
add a comment |
These two commands should work fine for a newbie
virtualenv -p python2 myenv
(For python2)
virtualenv -p python3 myenv
(For python3)
These two commands should work fine for a newbie
virtualenv -p python2 myenv
(For python2)
virtualenv -p python3 myenv
(For python3)
answered Jul 5 '18 at 10:03
Sachin KoligeSachin Kolige
17117
17117
1
The flag -p python2 works equivalent to looking for /usr/bin/python2. Use : virtualenv -p python2.7 myenv for 2.7 etc.
– Yash Sharma
Dec 28 '18 at 2:05
add a comment |
1
The flag -p python2 works equivalent to looking for /usr/bin/python2. Use : virtualenv -p python2.7 myenv for 2.7 etc.
– Yash Sharma
Dec 28 '18 at 2:05
1
1
The flag -p python2 works equivalent to looking for /usr/bin/python2. Use : virtualenv -p python2.7 myenv for 2.7 etc.
– Yash Sharma
Dec 28 '18 at 2:05
The flag -p python2 works equivalent to looking for /usr/bin/python2. Use : virtualenv -p python2.7 myenv for 2.7 etc.
– Yash Sharma
Dec 28 '18 at 2:05
add a comment |
You can call virtualenv
with python version you want. For example:
python3 -m virtualenv venv
Or alternatively directly point to your virtualenv path. e.g. for windows:
c:Python34Scriptsvirtualenv.exe venv
And by running:
venv/bin/python
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
you can see the python version installed in virtual environment
I got this error on running the first command /usr/local/bin/python3: No module named virtualenv
– tanvi
May 23 '16 at 13:48
2
@tanvi : You need to install virtualenv into your python3 first. Runpip3 install virtualenv
first
– Nima Soroush
May 23 '16 at 14:30
add a comment |
You can call virtualenv
with python version you want. For example:
python3 -m virtualenv venv
Or alternatively directly point to your virtualenv path. e.g. for windows:
c:Python34Scriptsvirtualenv.exe venv
And by running:
venv/bin/python
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
you can see the python version installed in virtual environment
I got this error on running the first command /usr/local/bin/python3: No module named virtualenv
– tanvi
May 23 '16 at 13:48
2
@tanvi : You need to install virtualenv into your python3 first. Runpip3 install virtualenv
first
– Nima Soroush
May 23 '16 at 14:30
add a comment |
You can call virtualenv
with python version you want. For example:
python3 -m virtualenv venv
Or alternatively directly point to your virtualenv path. e.g. for windows:
c:Python34Scriptsvirtualenv.exe venv
And by running:
venv/bin/python
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
you can see the python version installed in virtual environment
You can call virtualenv
with python version you want. For example:
python3 -m virtualenv venv
Or alternatively directly point to your virtualenv path. e.g. for windows:
c:Python34Scriptsvirtualenv.exe venv
And by running:
venv/bin/python
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
you can see the python version installed in virtual environment
edited Sep 19 '16 at 13:03
answered Dec 12 '15 at 23:11
Nima SoroushNima Soroush
6,72934050
6,72934050
I got this error on running the first command /usr/local/bin/python3: No module named virtualenv
– tanvi
May 23 '16 at 13:48
2
@tanvi : You need to install virtualenv into your python3 first. Runpip3 install virtualenv
first
– Nima Soroush
May 23 '16 at 14:30
add a comment |
I got this error on running the first command /usr/local/bin/python3: No module named virtualenv
– tanvi
May 23 '16 at 13:48
2
@tanvi : You need to install virtualenv into your python3 first. Runpip3 install virtualenv
first
– Nima Soroush
May 23 '16 at 14:30
I got this error on running the first command /usr/local/bin/python3: No module named virtualenv
– tanvi
May 23 '16 at 13:48
I got this error on running the first command /usr/local/bin/python3: No module named virtualenv
– tanvi
May 23 '16 at 13:48
2
2
@tanvi : You need to install virtualenv into your python3 first. Run
pip3 install virtualenv
first– Nima Soroush
May 23 '16 at 14:30
@tanvi : You need to install virtualenv into your python3 first. Run
pip3 install virtualenv
first– Nima Soroush
May 23 '16 at 14:30
add a comment |
The -p
approach works well, but you do have to remember to use it every time. If your goal is to switch to a newer version of Python generally, that's a pain and can also lead to mistakes.
Your other option is to set an environment variable that does the same thing as -p
. Set this via your ~/.bashrc
file or wherever you manage environment variables for your login sessions:
export VIRTUALENV_PYTHON=/path/to/desired/version
Then virtualenv
will use that any time you don't specify -p
on the command line.
This worked beautifully. Any idea why settingexport VIRTUALENVWRAPPER_PYTHON=/path/to/desired/version
per the virtualenvwrapper docs didn't work but this solution did work?
– YPCrumble
Nov 8 '16 at 22:37
That env var controls which Pythonvirtualenvwrapper
uses when run, nothing to do with installs.
– Chris Johnson
Nov 9 '16 at 1:47
This worked for me. No longer have to use -p every time I create a new virtualenv. Thanks!
– nedblorf
Apr 10 at 15:29
add a comment |
The -p
approach works well, but you do have to remember to use it every time. If your goal is to switch to a newer version of Python generally, that's a pain and can also lead to mistakes.
Your other option is to set an environment variable that does the same thing as -p
. Set this via your ~/.bashrc
file or wherever you manage environment variables for your login sessions:
export VIRTUALENV_PYTHON=/path/to/desired/version
Then virtualenv
will use that any time you don't specify -p
on the command line.
This worked beautifully. Any idea why settingexport VIRTUALENVWRAPPER_PYTHON=/path/to/desired/version
per the virtualenvwrapper docs didn't work but this solution did work?
– YPCrumble
Nov 8 '16 at 22:37
That env var controls which Pythonvirtualenvwrapper
uses when run, nothing to do with installs.
– Chris Johnson
Nov 9 '16 at 1:47
This worked for me. No longer have to use -p every time I create a new virtualenv. Thanks!
– nedblorf
Apr 10 at 15:29
add a comment |
The -p
approach works well, but you do have to remember to use it every time. If your goal is to switch to a newer version of Python generally, that's a pain and can also lead to mistakes.
Your other option is to set an environment variable that does the same thing as -p
. Set this via your ~/.bashrc
file or wherever you manage environment variables for your login sessions:
export VIRTUALENV_PYTHON=/path/to/desired/version
Then virtualenv
will use that any time you don't specify -p
on the command line.
The -p
approach works well, but you do have to remember to use it every time. If your goal is to switch to a newer version of Python generally, that's a pain and can also lead to mistakes.
Your other option is to set an environment variable that does the same thing as -p
. Set this via your ~/.bashrc
file or wherever you manage environment variables for your login sessions:
export VIRTUALENV_PYTHON=/path/to/desired/version
Then virtualenv
will use that any time you don't specify -p
on the command line.
answered Aug 5 '16 at 20:57
Chris JohnsonChris Johnson
12.8k35460
12.8k35460
This worked beautifully. Any idea why settingexport VIRTUALENVWRAPPER_PYTHON=/path/to/desired/version
per the virtualenvwrapper docs didn't work but this solution did work?
– YPCrumble
Nov 8 '16 at 22:37
That env var controls which Pythonvirtualenvwrapper
uses when run, nothing to do with installs.
– Chris Johnson
Nov 9 '16 at 1:47
This worked for me. No longer have to use -p every time I create a new virtualenv. Thanks!
– nedblorf
Apr 10 at 15:29
add a comment |
This worked beautifully. Any idea why settingexport VIRTUALENVWRAPPER_PYTHON=/path/to/desired/version
per the virtualenvwrapper docs didn't work but this solution did work?
– YPCrumble
Nov 8 '16 at 22:37
That env var controls which Pythonvirtualenvwrapper
uses when run, nothing to do with installs.
– Chris Johnson
Nov 9 '16 at 1:47
This worked for me. No longer have to use -p every time I create a new virtualenv. Thanks!
– nedblorf
Apr 10 at 15:29
This worked beautifully. Any idea why setting
export VIRTUALENVWRAPPER_PYTHON=/path/to/desired/version
per the virtualenvwrapper docs didn't work but this solution did work?– YPCrumble
Nov 8 '16 at 22:37
This worked beautifully. Any idea why setting
export VIRTUALENVWRAPPER_PYTHON=/path/to/desired/version
per the virtualenvwrapper docs didn't work but this solution did work?– YPCrumble
Nov 8 '16 at 22:37
That env var controls which Python
virtualenvwrapper
uses when run, nothing to do with installs.– Chris Johnson
Nov 9 '16 at 1:47
That env var controls which Python
virtualenvwrapper
uses when run, nothing to do with installs.– Chris Johnson
Nov 9 '16 at 1:47
This worked for me. No longer have to use -p every time I create a new virtualenv. Thanks!
– nedblorf
Apr 10 at 15:29
This worked for me. No longer have to use -p every time I create a new virtualenv. Thanks!
– nedblorf
Apr 10 at 15:29
add a comment |
For Mac(High Sierra), install the virtualenv on python3 and create a virtualenv for python2:
$ python3 -m pip install virtualenv
$ python3 -m virtualenv --python=python2 vp27
$ source vp27/bin/activate
(vp27)$ python --version
Python 2.7.14
1
Install virtualenv on python3 if you don't have:python3 -m pip install virtualenv
– Howe
Jul 3 '18 at 15:47
add a comment |
For Mac(High Sierra), install the virtualenv on python3 and create a virtualenv for python2:
$ python3 -m pip install virtualenv
$ python3 -m virtualenv --python=python2 vp27
$ source vp27/bin/activate
(vp27)$ python --version
Python 2.7.14
1
Install virtualenv on python3 if you don't have:python3 -m pip install virtualenv
– Howe
Jul 3 '18 at 15:47
add a comment |
For Mac(High Sierra), install the virtualenv on python3 and create a virtualenv for python2:
$ python3 -m pip install virtualenv
$ python3 -m virtualenv --python=python2 vp27
$ source vp27/bin/activate
(vp27)$ python --version
Python 2.7.14
For Mac(High Sierra), install the virtualenv on python3 and create a virtualenv for python2:
$ python3 -m pip install virtualenv
$ python3 -m virtualenv --python=python2 vp27
$ source vp27/bin/activate
(vp27)$ python --version
Python 2.7.14
edited Mar 6 at 16:31
answered Apr 24 '18 at 0:30
HoweHowe
17616
17616
1
Install virtualenv on python3 if you don't have:python3 -m pip install virtualenv
– Howe
Jul 3 '18 at 15:47
add a comment |
1
Install virtualenv on python3 if you don't have:python3 -m pip install virtualenv
– Howe
Jul 3 '18 at 15:47
1
1
Install virtualenv on python3 if you don't have:
python3 -m pip install virtualenv
– Howe
Jul 3 '18 at 15:47
Install virtualenv on python3 if you don't have:
python3 -m pip install virtualenv
– Howe
Jul 3 '18 at 15:47
add a comment |
On the mac I use pyenv and virtualenvwrapper. I had to create a new virtualenv. You need homebrew which I'll assume you've installed if you're on a mac, but just for fun:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install pyenv
pyenv install 2.7.10
pyenv global 2.7.10
export PATH=/Users/USERNAME/.pyenv/versions/2.7.10/bin:$PATH
mkvirtualenv -p ~/.pyenv/versions/2.7.10/bin/python virtual_env_name
I also froze my requirements first so i could simply reinstall in the new virtualenv with:
pip install -r requirements.txt
Command should bemkvirtualenv -p ~/.pyenv/versions/2.7.10/bin/python virtual_env_name
versions, not version. If SO allowed short edits, I woulda fixed it.
– Martin Burch
Sep 4 '15 at 4:30
pyenv
includes virtualenv support through thepyenv-virtualenv
plugin, so I find I don't really need virtualenvwrapper. More details in my pyenv answer.
– RichVel
May 7 '17 at 7:26
add a comment |
On the mac I use pyenv and virtualenvwrapper. I had to create a new virtualenv. You need homebrew which I'll assume you've installed if you're on a mac, but just for fun:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install pyenv
pyenv install 2.7.10
pyenv global 2.7.10
export PATH=/Users/USERNAME/.pyenv/versions/2.7.10/bin:$PATH
mkvirtualenv -p ~/.pyenv/versions/2.7.10/bin/python virtual_env_name
I also froze my requirements first so i could simply reinstall in the new virtualenv with:
pip install -r requirements.txt
Command should bemkvirtualenv -p ~/.pyenv/versions/2.7.10/bin/python virtual_env_name
versions, not version. If SO allowed short edits, I woulda fixed it.
– Martin Burch
Sep 4 '15 at 4:30
pyenv
includes virtualenv support through thepyenv-virtualenv
plugin, so I find I don't really need virtualenvwrapper. More details in my pyenv answer.
– RichVel
May 7 '17 at 7:26
add a comment |
On the mac I use pyenv and virtualenvwrapper. I had to create a new virtualenv. You need homebrew which I'll assume you've installed if you're on a mac, but just for fun:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install pyenv
pyenv install 2.7.10
pyenv global 2.7.10
export PATH=/Users/USERNAME/.pyenv/versions/2.7.10/bin:$PATH
mkvirtualenv -p ~/.pyenv/versions/2.7.10/bin/python virtual_env_name
I also froze my requirements first so i could simply reinstall in the new virtualenv with:
pip install -r requirements.txt
On the mac I use pyenv and virtualenvwrapper. I had to create a new virtualenv. You need homebrew which I'll assume you've installed if you're on a mac, but just for fun:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install pyenv
pyenv install 2.7.10
pyenv global 2.7.10
export PATH=/Users/USERNAME/.pyenv/versions/2.7.10/bin:$PATH
mkvirtualenv -p ~/.pyenv/versions/2.7.10/bin/python virtual_env_name
I also froze my requirements first so i could simply reinstall in the new virtualenv with:
pip install -r requirements.txt
edited Sep 4 '15 at 21:03
answered Sep 2 '15 at 22:04
silverdaggersilverdagger
482520
482520
Command should bemkvirtualenv -p ~/.pyenv/versions/2.7.10/bin/python virtual_env_name
versions, not version. If SO allowed short edits, I woulda fixed it.
– Martin Burch
Sep 4 '15 at 4:30
pyenv
includes virtualenv support through thepyenv-virtualenv
plugin, so I find I don't really need virtualenvwrapper. More details in my pyenv answer.
– RichVel
May 7 '17 at 7:26
add a comment |
Command should bemkvirtualenv -p ~/.pyenv/versions/2.7.10/bin/python virtual_env_name
versions, not version. If SO allowed short edits, I woulda fixed it.
– Martin Burch
Sep 4 '15 at 4:30
pyenv
includes virtualenv support through thepyenv-virtualenv
plugin, so I find I don't really need virtualenvwrapper. More details in my pyenv answer.
– RichVel
May 7 '17 at 7:26
Command should be
mkvirtualenv -p ~/.pyenv/versions/2.7.10/bin/python virtual_env_name
versions, not version. If SO allowed short edits, I woulda fixed it.– Martin Burch
Sep 4 '15 at 4:30
Command should be
mkvirtualenv -p ~/.pyenv/versions/2.7.10/bin/python virtual_env_name
versions, not version. If SO allowed short edits, I woulda fixed it.– Martin Burch
Sep 4 '15 at 4:30
pyenv
includes virtualenv support through the pyenv-virtualenv
plugin, so I find I don't really need virtualenvwrapper. More details in my pyenv answer.– RichVel
May 7 '17 at 7:26
pyenv
includes virtualenv support through the pyenv-virtualenv
plugin, so I find I don't really need virtualenvwrapper. More details in my pyenv answer.– RichVel
May 7 '17 at 7:26
add a comment |
Even easier, by using command substitution to find python2 for you:
virtualenv -p $(which python2) <path/to/new/virtualenv/>
Or when using virtualenvwrapper :
mkvirtualenv -p $(which python2) <env_name>
add a comment |
Even easier, by using command substitution to find python2 for you:
virtualenv -p $(which python2) <path/to/new/virtualenv/>
Or when using virtualenvwrapper :
mkvirtualenv -p $(which python2) <env_name>
add a comment |
Even easier, by using command substitution to find python2 for you:
virtualenv -p $(which python2) <path/to/new/virtualenv/>
Or when using virtualenvwrapper :
mkvirtualenv -p $(which python2) <env_name>
Even easier, by using command substitution to find python2 for you:
virtualenv -p $(which python2) <path/to/new/virtualenv/>
Or when using virtualenvwrapper :
mkvirtualenv -p $(which python2) <env_name>
answered Sep 19 '16 at 13:28
GerardGerard
2,39322028
2,39322028
add a comment |
add a comment |
In windows subsystem for linux:
Create environment for python3:
virtualenv --python=/usr/bin/python3 env
Activate it:
source env/bin/activate
add a comment |
In windows subsystem for linux:
Create environment for python3:
virtualenv --python=/usr/bin/python3 env
Activate it:
source env/bin/activate
add a comment |
In windows subsystem for linux:
Create environment for python3:
virtualenv --python=/usr/bin/python3 env
Activate it:
source env/bin/activate
In windows subsystem for linux:
Create environment for python3:
virtualenv --python=/usr/bin/python3 env
Activate it:
source env/bin/activate
answered May 26 '17 at 11:45
Marcin RapaczMarcin Rapacz
443512
443512
add a comment |
add a comment |
Yes, the above answers are correct and works fine on Unix based systems like Linux & MAC OS X.
I tried to create virtualenv for Python2 & Python3 with the following commands.
Here I have used venv2 & venv3 as their names for Python2 & Python3 respectively.
Python2 »
MacBook-Pro-2:~ admin$ virtualenv venv2 --python=`which python2`
Running virtualenv with interpreter /usr/local/bin/python2
New python executable in /Users/admin/venv2/bin/python
Installing setuptools, pip, wheel...done.
MacBook-Pro-2:~ admin$
MacBook-Pro-2:~ admin$ ls venv2/bin/
activate easy_install pip2.7 python2.7
activate.csh easy_install-2.7 python wheel
activate.fish pip python-config
activate_this.py pip2 python2
MacBook-Pro-2:~ admin$
Python3 »
MacBook-Pro-2:~ admin$ virtualenv venv3 --python=`which python3`
Running virtualenv with interpreter /usr/local/bin/python3
Using base prefix '/Library/Frameworks/Python.framework/Versions/3.6'
New python executable in /Users/admin/venv3/bin/python3
Also creating executable in /Users/admin/venv3/bin/python
Installing setuptools, pip, wheel...done.
MacBook-Pro-2:~ admin$
MacBook-Pro-2:~ admin$ ls venv3/bin/
activate easy_install pip3.6 python3.6
activate.csh easy_install-3.6 python wheel
activate.fish pip python-config
activate_this.py pip3 python3
MacBook-Pro-2:~ admin$
Checking Python installation locations
MacBook-Pro-2:~ admin$ which python2
/usr/local/bin/python2
MacBook-Pro-2:~ admin$
MacBook-Pro-2:~ admin$ which python3
/usr/local/bin/python3
MacBook-Pro-2:~ admin$
add a comment |
Yes, the above answers are correct and works fine on Unix based systems like Linux & MAC OS X.
I tried to create virtualenv for Python2 & Python3 with the following commands.
Here I have used venv2 & venv3 as their names for Python2 & Python3 respectively.
Python2 »
MacBook-Pro-2:~ admin$ virtualenv venv2 --python=`which python2`
Running virtualenv with interpreter /usr/local/bin/python2
New python executable in /Users/admin/venv2/bin/python
Installing setuptools, pip, wheel...done.
MacBook-Pro-2:~ admin$
MacBook-Pro-2:~ admin$ ls venv2/bin/
activate easy_install pip2.7 python2.7
activate.csh easy_install-2.7 python wheel
activate.fish pip python-config
activate_this.py pip2 python2
MacBook-Pro-2:~ admin$
Python3 »
MacBook-Pro-2:~ admin$ virtualenv venv3 --python=`which python3`
Running virtualenv with interpreter /usr/local/bin/python3
Using base prefix '/Library/Frameworks/Python.framework/Versions/3.6'
New python executable in /Users/admin/venv3/bin/python3
Also creating executable in /Users/admin/venv3/bin/python
Installing setuptools, pip, wheel...done.
MacBook-Pro-2:~ admin$
MacBook-Pro-2:~ admin$ ls venv3/bin/
activate easy_install pip3.6 python3.6
activate.csh easy_install-3.6 python wheel
activate.fish pip python-config
activate_this.py pip3 python3
MacBook-Pro-2:~ admin$
Checking Python installation locations
MacBook-Pro-2:~ admin$ which python2
/usr/local/bin/python2
MacBook-Pro-2:~ admin$
MacBook-Pro-2:~ admin$ which python3
/usr/local/bin/python3
MacBook-Pro-2:~ admin$
add a comment |
Yes, the above answers are correct and works fine on Unix based systems like Linux & MAC OS X.
I tried to create virtualenv for Python2 & Python3 with the following commands.
Here I have used venv2 & venv3 as their names for Python2 & Python3 respectively.
Python2 »
MacBook-Pro-2:~ admin$ virtualenv venv2 --python=`which python2`
Running virtualenv with interpreter /usr/local/bin/python2
New python executable in /Users/admin/venv2/bin/python
Installing setuptools, pip, wheel...done.
MacBook-Pro-2:~ admin$
MacBook-Pro-2:~ admin$ ls venv2/bin/
activate easy_install pip2.7 python2.7
activate.csh easy_install-2.7 python wheel
activate.fish pip python-config
activate_this.py pip2 python2
MacBook-Pro-2:~ admin$
Python3 »
MacBook-Pro-2:~ admin$ virtualenv venv3 --python=`which python3`
Running virtualenv with interpreter /usr/local/bin/python3
Using base prefix '/Library/Frameworks/Python.framework/Versions/3.6'
New python executable in /Users/admin/venv3/bin/python3
Also creating executable in /Users/admin/venv3/bin/python
Installing setuptools, pip, wheel...done.
MacBook-Pro-2:~ admin$
MacBook-Pro-2:~ admin$ ls venv3/bin/
activate easy_install pip3.6 python3.6
activate.csh easy_install-3.6 python wheel
activate.fish pip python-config
activate_this.py pip3 python3
MacBook-Pro-2:~ admin$
Checking Python installation locations
MacBook-Pro-2:~ admin$ which python2
/usr/local/bin/python2
MacBook-Pro-2:~ admin$
MacBook-Pro-2:~ admin$ which python3
/usr/local/bin/python3
MacBook-Pro-2:~ admin$
Yes, the above answers are correct and works fine on Unix based systems like Linux & MAC OS X.
I tried to create virtualenv for Python2 & Python3 with the following commands.
Here I have used venv2 & venv3 as their names for Python2 & Python3 respectively.
Python2 »
MacBook-Pro-2:~ admin$ virtualenv venv2 --python=`which python2`
Running virtualenv with interpreter /usr/local/bin/python2
New python executable in /Users/admin/venv2/bin/python
Installing setuptools, pip, wheel...done.
MacBook-Pro-2:~ admin$
MacBook-Pro-2:~ admin$ ls venv2/bin/
activate easy_install pip2.7 python2.7
activate.csh easy_install-2.7 python wheel
activate.fish pip python-config
activate_this.py pip2 python2
MacBook-Pro-2:~ admin$
Python3 »
MacBook-Pro-2:~ admin$ virtualenv venv3 --python=`which python3`
Running virtualenv with interpreter /usr/local/bin/python3
Using base prefix '/Library/Frameworks/Python.framework/Versions/3.6'
New python executable in /Users/admin/venv3/bin/python3
Also creating executable in /Users/admin/venv3/bin/python
Installing setuptools, pip, wheel...done.
MacBook-Pro-2:~ admin$
MacBook-Pro-2:~ admin$ ls venv3/bin/
activate easy_install pip3.6 python3.6
activate.csh easy_install-3.6 python wheel
activate.fish pip python-config
activate_this.py pip3 python3
MacBook-Pro-2:~ admin$
Checking Python installation locations
MacBook-Pro-2:~ admin$ which python2
/usr/local/bin/python2
MacBook-Pro-2:~ admin$
MacBook-Pro-2:~ admin$ which python3
/usr/local/bin/python3
MacBook-Pro-2:~ admin$
edited Jun 30 '18 at 7:42
answered Dec 16 '17 at 8:17
hygullhygull
4,06921632
4,06921632
add a comment |
add a comment |
It worked for me
sudo apt-get install python3-minimal
virtualenv --no-site-packages --distribute -p /usr/bin/python3 ~/.virtualenvs/py3
add a comment |
It worked for me
sudo apt-get install python3-minimal
virtualenv --no-site-packages --distribute -p /usr/bin/python3 ~/.virtualenvs/py3
add a comment |
It worked for me
sudo apt-get install python3-minimal
virtualenv --no-site-packages --distribute -p /usr/bin/python3 ~/.virtualenvs/py3
It worked for me
sudo apt-get install python3-minimal
virtualenv --no-site-packages --distribute -p /usr/bin/python3 ~/.virtualenvs/py3
answered Jun 3 '16 at 6:53
Dadaso ZanzaneDadaso Zanzane
4,03411921
4,03411921
add a comment |
add a comment |
On windows:
py -3.4x32 -m venv venv34
or
py -2.6.2 -m venv venv26
This uses the py
launcher which will find the right python executable for you (assuming you have it installed).
add a comment |
On windows:
py -3.4x32 -m venv venv34
or
py -2.6.2 -m venv venv26
This uses the py
launcher which will find the right python executable for you (assuming you have it installed).
add a comment |
On windows:
py -3.4x32 -m venv venv34
or
py -2.6.2 -m venv venv26
This uses the py
launcher which will find the right python executable for you (assuming you have it installed).
On windows:
py -3.4x32 -m venv venv34
or
py -2.6.2 -m venv venv26
This uses the py
launcher which will find the right python executable for you (assuming you have it installed).
answered Apr 17 '18 at 23:22
jnnnnnjnnnnn
2,3521728
2,3521728
add a comment |
add a comment |
virtualenv -p python3 myenv
Link to Creating virtualenv
add a comment |
virtualenv -p python3 myenv
Link to Creating virtualenv
add a comment |
virtualenv -p python3 myenv
Link to Creating virtualenv
virtualenv -p python3 myenv
Link to Creating virtualenv
answered Jul 3 '18 at 8:51
AseemAseem
8921120
8921120
add a comment |
add a comment |
For Debian (debian 9) Systems in 2019, I discovered a simple solution that may solve the problem from within the virtual environment.
Suppose the virtual environment were created via:
python3.7 -m venv myenv
but only has versions of python2
and python2.7
, and you need the recent features of python3.7.
Then, simply running the command:
(myvenv) $ python3.7 -m venv --upgrade /home/username/path/to/myvenv/
will add python3.7 packages if they are already available on your system.
add a comment |
For Debian (debian 9) Systems in 2019, I discovered a simple solution that may solve the problem from within the virtual environment.
Suppose the virtual environment were created via:
python3.7 -m venv myenv
but only has versions of python2
and python2.7
, and you need the recent features of python3.7.
Then, simply running the command:
(myvenv) $ python3.7 -m venv --upgrade /home/username/path/to/myvenv/
will add python3.7 packages if they are already available on your system.
add a comment |
For Debian (debian 9) Systems in 2019, I discovered a simple solution that may solve the problem from within the virtual environment.
Suppose the virtual environment were created via:
python3.7 -m venv myenv
but only has versions of python2
and python2.7
, and you need the recent features of python3.7.
Then, simply running the command:
(myvenv) $ python3.7 -m venv --upgrade /home/username/path/to/myvenv/
will add python3.7 packages if they are already available on your system.
For Debian (debian 9) Systems in 2019, I discovered a simple solution that may solve the problem from within the virtual environment.
Suppose the virtual environment were created via:
python3.7 -m venv myenv
but only has versions of python2
and python2.7
, and you need the recent features of python3.7.
Then, simply running the command:
(myvenv) $ python3.7 -m venv --upgrade /home/username/path/to/myvenv/
will add python3.7 packages if they are already available on your system.
answered Feb 23 at 21:45
David M. GolembiowskiDavid M. Golembiowski
112
112
add a comment |
add a comment |
This was a bug with virtualenv.
Just upgrading your pip should be the fix.
pip install --upgrade virtualenv
add a comment |
This was a bug with virtualenv.
Just upgrading your pip should be the fix.
pip install --upgrade virtualenv
add a comment |
This was a bug with virtualenv.
Just upgrading your pip should be the fix.
pip install --upgrade virtualenv
This was a bug with virtualenv.
Just upgrading your pip should be the fix.
pip install --upgrade virtualenv
answered Apr 4 at 9:19
MohitMohit
111
111
add a comment |
add a comment |
protected by Community♦ Jun 22 '14 at 19:41
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
8
Just mentioning that you can do this using virtualenvwrapper too.
– bias
May 28 '10 at 3:25
9
Worth noting that in python 3, there is a built-in virtualenv equivalent: venv.
– naught101
Sep 1 '14 at 12:47
1
Is it not possible to switch python version in the current environment without creating a new environment?
– Charlie Parker
Aug 28 '16 at 23:38