virtualenvwrapper and Python 3

后端 未结 9 1983
执念已碎
执念已碎 2020-12-22 17:06

I installed python 3.3.1 on ubuntu lucid and successfully created a virtualenv as below

virtualenv envpy331 --python=/usr/local/bin/python3.3
相关标签:
9条回答
  • 2020-12-22 17:42

    On Ubuntu; using mkvirtualenv -p python3 env_name loads the virtualenv with python3.

    Inside the env, use python --version to verify.

    0 讨论(0)
  • 2020-12-22 17:44

    The latest version of virtualenvwrapper is tested under Python3.2. Chances are good it will work with Python3.3 too.

    0 讨论(0)
  • 2020-12-22 17:45

    I added export VIRTUALENV_PYTHON=/usr/bin/python3 to my ~/.bashrc like this:

    export WORKON_HOME=$HOME/.virtualenvs
    export VIRTUALENV_PYTHON=/usr/bin/python3
    source /usr/local/bin/virtualenvwrapper.sh
    

    then run source .bashrc

    and you can specify the python version for each new env mkvirtualenv --python=python2 env_name

    0 讨论(0)
  • 2020-12-22 17:52

    You can add this to your .bash_profile or similar:

    alias mkvirtualenv3='mkvirtualenv --python=`which python3`'
    

    Then use mkvirtualenv3 instead of mkvirtualenv when you want to create a python 3 environment.

    0 讨论(0)
  • 2020-12-22 17:58

    I find that running

    export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
    

    and

    export VIRTUALENVWRAPPER_VIRTUALENV=/usr/bin/virtualenv-3.4
    

    in the command line on Ubuntu forces mkvirtualenv to use python3 and virtualenv-3.4. One still has to do

    mkvirtualenv --python=/usr/bin/python3 nameOfEnvironment
    

    to create the environment. This is assuming that you have python3 in /usr/bin/python3 and virtualenv-3.4 in /usr/local/bin/virtualenv-3.4.

    0 讨论(0)
  • 2020-12-22 18:02

    If you already have python3 installed as well virtualenvwrapper the only thing you would need to do to use python3 with the virtual environment is creating an environment using:

    which python3 #Output: /usr/bin/python3
    mkvirtualenv --python=/usr/bin/python3 nameOfEnvironment
    

    Or, (at least on OSX using brew):

    mkvirtualenv --python=`which python3` nameOfEnvironment
    

    Start using the environment and you'll see that as soon as you type python you'll start using python3

    0 讨论(0)
提交回复
热议问题