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;








906















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?










share|improve this question



















  • 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

















906















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?










share|improve this question



















  • 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













906












906








906


404






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?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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












  • 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












21 Answers
21






active

oldest

votes


















1324














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.






share|improve this answer




















  • 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



















192














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.






share|improve this answer




















  • 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






  • 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






  • 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


















172














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.






share|improve this answer




















  • 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 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





    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


















97














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





share|improve this answer




















  • 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 out python3.6 but dont want to touch python3.5 installed on your computer?

    – alpha_989
    Jul 31 '18 at 3:53


















75














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`





share|improve this answer




















  • 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 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











  • 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


















67














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.






share|improve this answer






























    28














    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.






    share|improve this answer

























    • 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, 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



















    20














    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.






    share|improve this answer

























    • 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


















    14














    These two commands should work fine for a newbie



    virtualenv -p python2 myenv (For python2)



    virtualenv -p python3 myenv (For python3)






    share|improve this answer


















    • 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



















    10














    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






    share|improve this answer

























    • 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. Run pip3 install virtualenv first

      – Nima Soroush
      May 23 '16 at 14:30


















    8














    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.






    share|improve this answer























    • 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












    • This worked for me. No longer have to use -p every time I create a new virtualenv. Thanks!

      – nedblorf
      Apr 10 at 15:29


















    8














    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





    share|improve this answer




















    • 1





      Install virtualenv on python3 if you don't have: python3 -m pip install virtualenv

      – Howe
      Jul 3 '18 at 15:47


















    6














    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





    share|improve this answer

























    • 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



















    6














    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>






    share|improve this answer






























      4














      In windows subsystem for linux:




      1. Create environment for python3:



        virtualenv --python=/usr/bin/python3 env



      2. Activate it:



        source env/bin/activate






      share|improve this answer






























        3














        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$





        share|improve this answer
































          2














          It worked for me



          sudo apt-get install python3-minimal

          virtualenv --no-site-packages --distribute -p /usr/bin/python3 ~/.virtualenvs/py3





          share|improve this answer






























            2














            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).






            share|improve this answer






























              1














              virtualenv -p python3 myenv


              Link to Creating virtualenv






              share|improve this answer






























                0














                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.






                share|improve this answer






























                  0














                  This was a bug with virtualenv.
                  Just upgrading your pip should be the fix.



                  pip install --upgrade virtualenv






                  share|improve this answer





















                    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









                    1324














                    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.






                    share|improve this answer




















                    • 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
















                    1324














                    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.






                    share|improve this answer




















                    • 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














                    1324












                    1324








                    1324







                    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.






                    share|improve this answer















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



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


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







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    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













                    • 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














                    192














                    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.






                    share|improve this answer




















                    • 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






                    • 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






                    • 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















                    192














                    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.






                    share|improve this answer




















                    • 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






                    • 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






                    • 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













                    192












                    192








                    192







                    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.






                    share|improve this answer















                    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.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    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 as python3 -m venv <envname> to prevent needing stub scripts for everything.

                      – Paul Everitt
                      Nov 20 '16 at 16:08






                    • 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






                    • 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












                    • 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






                    • 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






                    • 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







                    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











                    172














                    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.






                    share|improve this answer




















                    • 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 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





                      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















                    172














                    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.






                    share|improve this answer




















                    • 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 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





                      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













                    172












                    172








                    172







                    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.






                    share|improve this answer















                    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.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    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 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





                      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





                      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 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





                      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











                    97














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





                    share|improve this answer




















                    • 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 out python3.6 but dont want to touch python3.5 installed on your computer?

                      – alpha_989
                      Jul 31 '18 at 3:53















                    97














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





                    share|improve this answer




















                    • 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 out python3.6 but dont want to touch python3.5 installed on your computer?

                      – alpha_989
                      Jul 31 '18 at 3:53













                    97












                    97








                    97







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





                    share|improve this answer















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






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    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 out python3.6 but dont want to touch python3.5 installed on your computer?

                      – alpha_989
                      Jul 31 '18 at 3:53












                    • 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 out python3.6 but dont want to touch python3.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











                    75














                    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`





                    share|improve this answer




















                    • 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 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











                    • 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















                    75














                    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`





                    share|improve this answer




















                    • 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 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











                    • 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













                    75












                    75








                    75







                    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`





                    share|improve this answer















                    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`






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    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 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











                    • 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





                      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











                    • 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











                    67














                    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.






                    share|improve this answer



























                      67














                      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.






                      share|improve this answer

























                        67












                        67








                        67







                        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.






                        share|improve this answer













                        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.







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Jul 31 '11 at 21:04









                        balazsbalazs

                        4,17852943




                        4,17852943





















                            28














                            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.






                            share|improve this answer

























                            • 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, 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
















                            28














                            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.






                            share|improve this answer

























                            • 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, 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














                            28












                            28








                            28







                            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.






                            share|improve this answer















                            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.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            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, 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


















                            • 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, 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

















                            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












                            20














                            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.






                            share|improve this answer

























                            • 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















                            20














                            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.






                            share|improve this answer

























                            • 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













                            20












                            20








                            20







                            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.






                            share|improve this answer















                            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.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            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

















                            • 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











                            14














                            These two commands should work fine for a newbie



                            virtualenv -p python2 myenv (For python2)



                            virtualenv -p python3 myenv (For python3)






                            share|improve this answer


















                            • 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
















                            14














                            These two commands should work fine for a newbie



                            virtualenv -p python2 myenv (For python2)



                            virtualenv -p python3 myenv (For python3)






                            share|improve this answer


















                            • 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














                            14












                            14








                            14







                            These two commands should work fine for a newbie



                            virtualenv -p python2 myenv (For python2)



                            virtualenv -p python3 myenv (For python3)






                            share|improve this answer













                            These two commands should work fine for a newbie



                            virtualenv -p python2 myenv (For python2)



                            virtualenv -p python3 myenv (For python3)







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            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













                            • 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












                            10














                            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






                            share|improve this answer

























                            • 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. Run pip3 install virtualenv first

                              – Nima Soroush
                              May 23 '16 at 14:30















                            10














                            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






                            share|improve this answer

























                            • 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. Run pip3 install virtualenv first

                              – Nima Soroush
                              May 23 '16 at 14:30













                            10












                            10








                            10







                            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






                            share|improve this answer















                            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







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            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. Run pip3 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






                            • 2





                              @tanvi : You need to install virtualenv into your python3 first. Run pip3 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











                            8














                            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.






                            share|improve this answer























                            • 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












                            • This worked for me. No longer have to use -p every time I create a new virtualenv. Thanks!

                              – nedblorf
                              Apr 10 at 15:29















                            8














                            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.






                            share|improve this answer























                            • 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












                            • This worked for me. No longer have to use -p every time I create a new virtualenv. Thanks!

                              – nedblorf
                              Apr 10 at 15:29













                            8












                            8








                            8







                            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.






                            share|improve this answer













                            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.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Aug 5 '16 at 20:57









                            Chris JohnsonChris Johnson

                            12.8k35460




                            12.8k35460












                            • 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












                            • 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











                            • 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 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











                            8














                            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





                            share|improve this answer




















                            • 1





                              Install virtualenv on python3 if you don't have: python3 -m pip install virtualenv

                              – Howe
                              Jul 3 '18 at 15:47















                            8














                            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





                            share|improve this answer




















                            • 1





                              Install virtualenv on python3 if you don't have: python3 -m pip install virtualenv

                              – Howe
                              Jul 3 '18 at 15:47













                            8












                            8








                            8







                            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





                            share|improve this answer















                            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






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            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












                            • 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











                            6














                            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





                            share|improve this answer

























                            • 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
















                            6














                            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





                            share|improve this answer

























                            • 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














                            6












                            6








                            6







                            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





                            share|improve this answer















                            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






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Sep 4 '15 at 21:03

























                            answered Sep 2 '15 at 22:04









                            silverdaggersilverdagger

                            482520




                            482520












                            • 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


















                            • 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

















                            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












                            6














                            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>






                            share|improve this answer



























                              6














                              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>






                              share|improve this answer

























                                6












                                6








                                6







                                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>






                                share|improve this answer













                                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>







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Sep 19 '16 at 13:28









                                GerardGerard

                                2,39322028




                                2,39322028





















                                    4














                                    In windows subsystem for linux:




                                    1. Create environment for python3:



                                      virtualenv --python=/usr/bin/python3 env



                                    2. Activate it:



                                      source env/bin/activate






                                    share|improve this answer



























                                      4














                                      In windows subsystem for linux:




                                      1. Create environment for python3:



                                        virtualenv --python=/usr/bin/python3 env



                                      2. Activate it:



                                        source env/bin/activate






                                      share|improve this answer

























                                        4












                                        4








                                        4







                                        In windows subsystem for linux:




                                        1. Create environment for python3:



                                          virtualenv --python=/usr/bin/python3 env



                                        2. Activate it:



                                          source env/bin/activate






                                        share|improve this answer













                                        In windows subsystem for linux:




                                        1. Create environment for python3:



                                          virtualenv --python=/usr/bin/python3 env



                                        2. Activate it:



                                          source env/bin/activate







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered May 26 '17 at 11:45









                                        Marcin RapaczMarcin Rapacz

                                        443512




                                        443512





















                                            3














                                            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$





                                            share|improve this answer





























                                              3














                                              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$





                                              share|improve this answer



























                                                3












                                                3








                                                3







                                                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$





                                                share|improve this answer















                                                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$






                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited Jun 30 '18 at 7:42

























                                                answered Dec 16 '17 at 8:17









                                                hygullhygull

                                                4,06921632




                                                4,06921632





















                                                    2














                                                    It worked for me



                                                    sudo apt-get install python3-minimal

                                                    virtualenv --no-site-packages --distribute -p /usr/bin/python3 ~/.virtualenvs/py3





                                                    share|improve this answer



























                                                      2














                                                      It worked for me



                                                      sudo apt-get install python3-minimal

                                                      virtualenv --no-site-packages --distribute -p /usr/bin/python3 ~/.virtualenvs/py3





                                                      share|improve this answer

























                                                        2












                                                        2








                                                        2







                                                        It worked for me



                                                        sudo apt-get install python3-minimal

                                                        virtualenv --no-site-packages --distribute -p /usr/bin/python3 ~/.virtualenvs/py3





                                                        share|improve this answer













                                                        It worked for me



                                                        sudo apt-get install python3-minimal

                                                        virtualenv --no-site-packages --distribute -p /usr/bin/python3 ~/.virtualenvs/py3






                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered Jun 3 '16 at 6:53









                                                        Dadaso ZanzaneDadaso Zanzane

                                                        4,03411921




                                                        4,03411921





















                                                            2














                                                            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).






                                                            share|improve this answer



























                                                              2














                                                              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).






                                                              share|improve this answer

























                                                                2












                                                                2








                                                                2







                                                                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).






                                                                share|improve this answer













                                                                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).







                                                                share|improve this answer












                                                                share|improve this answer



                                                                share|improve this answer










                                                                answered Apr 17 '18 at 23:22









                                                                jnnnnnjnnnnn

                                                                2,3521728




                                                                2,3521728





















                                                                    1














                                                                    virtualenv -p python3 myenv


                                                                    Link to Creating virtualenv






                                                                    share|improve this answer



























                                                                      1














                                                                      virtualenv -p python3 myenv


                                                                      Link to Creating virtualenv






                                                                      share|improve this answer

























                                                                        1












                                                                        1








                                                                        1







                                                                        virtualenv -p python3 myenv


                                                                        Link to Creating virtualenv






                                                                        share|improve this answer













                                                                        virtualenv -p python3 myenv


                                                                        Link to Creating virtualenv







                                                                        share|improve this answer












                                                                        share|improve this answer



                                                                        share|improve this answer










                                                                        answered Jul 3 '18 at 8:51









                                                                        AseemAseem

                                                                        8921120




                                                                        8921120





















                                                                            0














                                                                            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.






                                                                            share|improve this answer



























                                                                              0














                                                                              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.






                                                                              share|improve this answer

























                                                                                0












                                                                                0








                                                                                0







                                                                                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.






                                                                                share|improve this answer













                                                                                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.







                                                                                share|improve this answer












                                                                                share|improve this answer



                                                                                share|improve this answer










                                                                                answered Feb 23 at 21:45









                                                                                David M. GolembiowskiDavid M. Golembiowski

                                                                                112




                                                                                112





















                                                                                    0














                                                                                    This was a bug with virtualenv.
                                                                                    Just upgrading your pip should be the fix.



                                                                                    pip install --upgrade virtualenv






                                                                                    share|improve this answer



























                                                                                      0














                                                                                      This was a bug with virtualenv.
                                                                                      Just upgrading your pip should be the fix.



                                                                                      pip install --upgrade virtualenv






                                                                                      share|improve this answer

























                                                                                        0












                                                                                        0








                                                                                        0







                                                                                        This was a bug with virtualenv.
                                                                                        Just upgrading your pip should be the fix.



                                                                                        pip install --upgrade virtualenv






                                                                                        share|improve this answer













                                                                                        This was a bug with virtualenv.
                                                                                        Just upgrading your pip should be the fix.



                                                                                        pip install --upgrade virtualenv







                                                                                        share|improve this answer












                                                                                        share|improve this answer



                                                                                        share|improve this answer










                                                                                        answered Apr 4 at 9:19









                                                                                        MohitMohit

                                                                                        111




                                                                                        111















                                                                                            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?



                                                                                            Popular posts from this blog

                                                                                            Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                                                                                            Compiling GNU Global with universal-ctags support 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!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                                                                                            Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved