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.
- 305
- 1
- 3
- 9
3 Answers
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.
-
1Yeah i know that once installed the new Python folder is created in Applications, but how i update the PATH variable? – g_rmz Jun 19 '14 at 06:45
-
I've updated the answer. – Vortico Jun 19 '14 at 06:50
-
2`.bashrc` is not used on OS X. You need `.bash_profile`. Also don't forget to quote the `$PATH`, e.g. `export PATH="/path/to/bin/folder:$PATH"` – slhck Jun 19 '14 at 06:50
-
The new Python already done the update of the shell by himself! But now that i have installed pygame when i try to import it i receive – g_rmz Jun 19 '14 at 07:14
-
"Traceback (most recent call last): File "
", line 1, in – g_rmz Jun 19 '14 at 07:18File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py", line 95, in from pygame.base import * ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so, 2): no suitable image found. Did find: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so: no matching architecture in universal wrapper" -
I have changed this but I still cannot get it to work. I didn't point to a /bin folder. – Script Kitty Dec 14 '16 at 03:02
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.
- 223,558
- 70
- 607
- 592