Install and use multiple Python versions

First, we need to list the all available versions of Python, including Anaconda, Jython, pypy, and stackless in our system. Use the following command to list them all:

$ pyenv install --list

Now, that you have a list you can decide which versions of Python you want to install. You can install the desired versions with the following command:

$ pyenv install 3.5.2
$ pyenv install 2.7.12

Last step before use the desired version, now that you have installed the latest and required version we need to set the priority of the version to use. The global command allows us to set global version(s) of Python to be used in all shells. Thus, if we want to use version 2.7.12 over version 3.5.2 following command will do the trick:

$ pyenv global 2.7.12 3.5.2
$ pyenv rehash

Remember, the leading version always takes priority so in our case v2.7.12 is going to be the default.

All installed Python versions can be located in ~/.pyenv/versions. Alternatively, you can run:

$ pyenv versions
  system (set by /Users/your_account/.pyenv/version)
* 2.7.12
* 3.5.2

This shows an asterisk * next to the currently active version.

Last updated