MacOS – command line update of python3

command linemacospythonsoftware-updateterminal

I have both python 2.7 and 3.5.1 installed in my Mac (El Capitan). I left version 2.7 as per this recommendation.

Now I would like to update version 3.5.1 to the latest one but from the command line. Is there a way to do that (preferably from within python itself)?

Best Answer

You can easily switch versions of Python using pyenv.

For example (using Homebrew):

$ brew update
$ brew install pyenv
$ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile

$ exec $SHELL

$ pyenv install 2.7.12
$ pyenv install 3.5.2
$ pyenv global 2.7.12 3.5.2

$ python -V
Python 2.7.12

$ python2 -V
Python 2.7.12

$ python2.7 -V
Python 2.7.12

$ python3 -V
Python 3.5.2

$ python3.5 -V
Python 3.5.2