Search code examples
pythonpython-3.xvirtualenvpyenv

Set two different python versions with pyenv with different names?


Is it possible to set two different python versions for different names using pyenv? E.g. I want the python3 refer to version 3.7.4 but python refer to version 2 of python defined by system which is 2.7.12 so there will not be any conflicts and issues.

Currently I just can set version globally using pyenv global 3.7.4 which cause both python and python3 be version 3.7.4.


Solution

  • Pyenv allows you to use different versions of Python at once using "advanced" mode

    Example from documentation:

    $ pyenv local 2.7.6 3.3.3
    $ pyenv versions
      system
    * 2.7.6 (set by /Users/yyuu/path/to/project/.python-version)
    * 3.3.3 (set by /Users/yyuu/path/to/project/.python-version)
    $ python --version
    Python 2.7.6
    $ python2.7 --version
    Python 2.7.6
    $ python3.3 --version
    Python 3.3.3
    

    For more information, please look at: https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-local-advanced