osx - How to update Mac's system Python

07
2014-07
  • g_rmz

    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.

  • Answers
  • Vortico

    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, discover the absolute folder path containing the python binary. This may look something like /Applications/Python/.../bin. Add the following line to your ~/.bashrc file.

    export PATH={path to bin folder}:$PATH
    

    and restart your shell.

  • Sai

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


  • Related Question

    osx - How do I properly update Python on Mac OS X
  • Philippe Mongeau

    If I download python from the Python website and try to install it with the installer, it installs, but I need to specify that I want the new version of Python when I run my programs from terminal. If I just type:

    python app.py
    

    It runs with the old version.

    How do can I set the new version as default?


  • Related Answers
  • Philippe Mongeau

    I finally found how to do it. The installer made a python 2.6 folder in /Application In this folder is a script called Update Shell Profile.command I just needed to execute it and now it's working.

  • Telemachus

    Two questions:

    1. Where did the new Python get installed?
    2. What does your $PATH look like?

    A default set-up on Unix-like systems is that user-installed software gets installed in /usr/local/bin, and most *nix distros put that directory before system-wide directories in the default $PATH variable (which is how your shell knows where to look for programs). That way, if you install something new, the new item gets found first.

    However, a default OS X $PATH looks like this:

    /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
    

    The problem is that by putting /usr/local/bin so late, the system-wide Python (which is at /usr/bin and so earlier in your $PATH) keeps getting hit.

    My answer is to make my $PATH look like this on a Mac:

    /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin
    

    To do that, create a file .profile in your home directory and add something like this:

    #### Let's take care of our $PATH
    # A backup of the original $PATH
    # /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
    
    # My preferred order - /usr/local goes first, damn it!
    PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin
    

    Edit: I'm following up here, rather than in comments because it's getting too long for a comment. The line in your .profile with /sw/bin/init.sh comes from the package manager Fink, which I'm assuming you use (or used at some point). The other line seems to suggest that at some point you installed MacPython and it rewrote your $PATH for you. I don't know MacPython, but if it's this site, then it hasn't been updated since 2004. It also doesn't seem to talk about any version of OS X beyond 10.3, which is not very current.

    So now I'm more confused: when did you update Python? How did you update it? What version of OS X are you running?

  • Bill Weiss

    Find out where python lives:

    $ which python
    /usr/bin/python
    

    See if it's a symlink:

    $ ls -Fal /usr/bin/python
    lrwxr-xr-x  1 root wheel  72 May 19 12:02 /usr/bin/python@ -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python
    

    If so, link /usr/bin/python to the new python:

    $ sudo ln -s (new python, maybe /System/Library/Frameworks/Python.framework/Versions/2.x/bin/python) /usr/bin/python
    

    Check if it works:

    $ python --version
    Python 2.xxx