Question

On doing 'which Python' it says '/usr/local/bin/python'. But when I go there through 'finder' there's nothing there. I can see /Library/Python through finder and on clicking Library/Python I see 2.3, 2.5, 2.6, 2.7.

The default Python currently is 2.7which I can see with --version. But all it has is /site-packages. How is this possible? I am not sure if it is the one that came with the OS or if it was installed later by someone. I am so so confused.

OSX 10.8.4

Was it helpful?

Solution

What you have found is just a symlink to the python binary, try doing:

ls -l /usr/local/bin/python

this will show you where this simlink is pointing to. For example I get (see the end of the line):

lrwxr-xr-x  1 yaser  admin  33 Mar 30 15:59 /usr/local/bin/python -> ../Cellar/python/2.7.3/bin/python

Normally it is located at:

/Library/Frameworks/Python.framework/Versions/2.7/

OTHER TIPS

First, /usr/local/bin/python is not the Apple-supplied Python; that's always in /usr/bin/python.

Second, /Library/Python/X.Y is not supposed to have anything but site-packages. In particular, that's where you put packages that you want to be shared by all framework builds of PythonX.Y on the system. (There's also /usr/local/lib/pythonX.Y, which also has a site-packages, intended for packages that you want to be shared by all builds, framework and non-framework.)

The actual Apple-supplied Python itself is in /System/Library/Frameworks/Python.framework.

Most third-party framework builds are in /Library/Frameworks/Python.framework. However, Homebrew, MacPorts, and Fink all install to different places. For example, Homebrew will install to `/usr/local/Cellar/python/X.Y.Z/Frameworks/Python.framework.

Non-framework builds instead go into somewhere like /usr/local/share/pythonX.Y—although again, Homebrew, MacPorts, and Fink install to different places.

Finally, many installations will create symlinks (or, sometimes, wrapper scripts) to more typical places. In particular, /usr/local/bin/python is likely a symlink to Versions/X.Y/bin/python inside the appropriate Python.framework as explained above.


If this is all too confusing for you to even comprehend, the simplest thing to do is to uninstall the extra Python2.7 that you installed, and just use Apple's. There are certainly good reasons for some people to have another Python 2.7 around (the blog post linked above shows a number of them), but if you don't have such a reason, why make things harder on yourself?

Since it looks like you're using Homebrew, you can even nondestructively test whether getting it out of the way causes any problems: brew unlink python will remove all traces of the Homebrew Python from your normal PATH, but leave the actual files behind. Then, if you want it back, just brew link python; if you're happier without it, brew uninstall python.

It's worth noting that many common reasons for thinking you need multiple PythonX.Y installations can be solved much more easily, and cleanly, by using virtualenv.


If you're using MacPorts or Fink, they're explicitly designed to try to stay out of the way of the standard system locations. So, everything will be installed somewhere under your MacPorts/Fink root, which defaults to /opt/local or /sw, respectively. (I'll assume /opt/local.) That means a framework build will go somewhere like /opt/local/Library/Frameworks, with symlinks into /opt/local/bin and /opt/local/lib and the like. The site packages will be in /opt/local/Library/Python/X.Y and/or /opt/local/lib/pythonX.Y.

So, there's no possibility of any conflict with any other Python installation… except, of course, that /opt/local/bin and /usr/local/bin are probably both on your PATH, it's still possible that pip means /usr/local/bin/pip from the Apple or Python.org installation, while ipython means /opt/local/bin/ipython from the MacPorts one…

In addition to following the symlink you can import a package and type the name of the package to find where it is on disk:

>>> import crypt
>>> crypt
<module 'crypt' from '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/crypt.so'>

/usr and several other system paths are not visible in the Finder.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top