How to update Mac's system Python
I'm on Mavericks at the moment, and i want to update the Python system's version (2.7.5) to the latest (2.7.7) from http://www.python.org, because i want to install pygame.
What i have to do? I would like to be able to run the latest version of Python when i type python
in the terminal, i searched for some guide on the net but it's all a bit confusing to me.
Replacing Mac OS X's system Python is not recommended due to incompatability with other software. However, there are Mac binaries on the Python download page that can be installed to a different location. Once installed, you may need to change your PATH environment variable so the new Python interpreter will run when python
is invoked from the command line.
To edit your PATH, determine the absolute folder path containing the Python binary. This may look something like /Applications/Python/.../bin
. Add the following line to your ~/.bash_profile
file:
export PATH=/path/to/new/python/bin:$PATH
The change will take effect after you restart your shell.
The easiest, non-intrusive way would be to use Homebrew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Then, read the instructions that are printed from your shell.
Installing Python 3
With Homebrew you can install Python 3.x:
brew install python
This will put a python3
binary in /usr/local/bin
, and a python
binary pointing to python3
in /usr/local/opt/python/libexec/bin
.
You will additionally get a pip3
command for that version of Python.
These formulas will not conflict or take precedence over the system packages unless you override your PATH
. That is, if you want python
to refer to python3
, add the following to your shell config:
export PATH=/usr/local/opt/python/libexec/bin:$PATH
Read the Homebrew Python docs for more info.
Installing Python 2.7
You can also get an up-to-date version of Python 2.7, if you require that for legacy reasons:
brew install python@2
This will give you a python2
binary, and it will override the system python
to use the Homebrew-built Python 2.7.