'usr/bin/python' and 'python' run different versions

11,214

The version in /usr/bin/python is the version installed as part of OS X. Type 'which python' to find out where your newer python version is located. You've probably installed a newer version via MacPorts or the like.

It might be dangerous to change where /usr/bin/python points to in case it is needed by other apps. You can change your python scripts so that they find the user's version of python by changing the first line from:

#!/usr/bin/python

to:

#!/bin/env python

If you really want to replace /usr/bin/python, you can do it like this:

sudo mv /usr/bin/python /usr/bin/python.dist
sudo ln -s `which python` /usr/bin/python

However, like I said, that might be dangerous. If you need to revert this change later you can run:

sudo rm /usr/bin/python
sudo mv /usr/bin/python.dist /usr/bin/python

Please run these with care though. If you accidentally remove your system installed python version on OS X there will be some pain involved in getting it back.

Share:
11,214

Related videos on Youtube

CCC
Author by

CCC

Updated on September 18, 2022

Comments

  • CCC
    CCC over 1 year

    On my OS X typing /usr/bin/python in to terminal runs Python 2.6.1, but typing python runs Python 2.7.2. I'd like the former to run 2.7.2 as well - how do I do this?

  • Gordon Davisson
    Gordon Davisson almost 12 years
    Agreed. Also, future updates from Apple may replace the symlink and effectively revert the change, or possibly (depending on exactly how the installer works -- I haven't tested) follow the symlink and replace the 2.7.2 version you've built with something else.