1

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

  • The SO post you linked has several answers. How did you install 3.5.1? – bmike Apr 9 '17 at 3:11
2

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
1

I'd use homebrew so you could upgrade or install using a one line command:

brew install python3 && brew upgrade python3
-1

Unfortunately, there isn't another way from the command line other than installing Homebrew, an unofficial package manager for macOS and then typing brew install python3.

This method does pose some issues. When installing Python via Homebrew, it does not remove any old version of Python (for compatibility reasons). This means old versions could be sitting on your hard drive, taking up space that could be used for something else. Another possible issue with Homebrew is that it needs Xcode to be installed so that it can compile and install Python on-device (and the current version of Xcode takes up 10+ gigs of HD space, not to factor in the space to store the source code).

The preferred and official way to install Python is via their .pkg installer available at their website, but this doesn't remove old Python3 installations either (again, for the same reasons).

So it all comes down to how you want to go about installing Python. There are many different ways, and I only listed the ones that seem most relevant to your situation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .