17

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.

9

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.

  • 1
    Yeah 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 6:45
  • I've updated the answer. – Vortico Jun 19 '14 at 6: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 6: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 7:14
  • "Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py", line 95, in <module> 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" – g_rmz Jun 19 '14 at 7:18
5

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.

0

Have you tried installing port?. I recently upgraded my python with port install on 10.8.4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.