Why install a third-party Python 2.7?
Python.org, Homebrew, scipy.org, 69105 different blog posts explaining how to install numpy/scipy/etc. on a Mac, etc. all tell you to install a different Python alongside Apple's. Almost nobody tells you to just use Apple's (except Homebrew, but they also tell you the opposite…).There are some good reasons to install a third-party Python 2.7 on your Mac. If any of these apply, go install it:
- You have an older OS X that doesn't come with 2.7.
- You need one of the fixes in the latest 2.7.x.
- You plan to use py2app to distribute binary applications. (As of 0.7.3, you can only build "semi-standalone" apps against 64-bit Apple Python.)
- You don't have admin access, and for some reason can't install virtualenv into a user site-packages directory and do everything inside a venv.
- You need an extra-batteries Python like Enthought.
- You need the absolutely exact same Python on your 10.8 and 10.6 machines, or even (as far as ActiveState can make possible) on your Windows and Linux machines.
- You use a non-usr-root package manager like MacPorts, Fink, or gentoo-alt.
- You're hacking on the Python 2.x source.
But if none of those apply, do you really need another 2.7? Because there are an awful lot of downsides.
Why not install a third-party Python 2.7?
Parallel installs of the same minor version suck
Python is designed to handle parallel installs—but it does so by using X.Y directories and suffixes. So, if you have two 2.7s, you get:
- Executable path collisions. Most Python installations will try to install extra scripts and executables like pip, ipython, etc. into /usr/local/bin. So, you'll end up silently replacing your python.org-Python ipython with an Apple-Python ipython. And "ipython-2.7" doesn't help, because they're both called that.
- Executable name collisions. Even if they're in different directories, what gets run by "python2.7" or "pip-2.7" depends on which is higher on your path.
- Site-packages collisions. There are a variety of site-packages directories, like /Library/Python/2.7, which will be shared by all of your 2.7 builds. That's usually fine for pure-Python code, but a C extension (like numpy or lxml) built for one Python 2.7 may insta-crash the other 2.7 if you're lucky, or cause instability or incorrect results if you're not.
$PATH Management is painful, even more so on Mac than other *nix
By default, /usr/local/bin comes later in the PATH than /usr/bin for shell scripts and sessions, and isn't on the path at all for GUI apps and LaunchAgents. So, when you type "python" or "python2.7", you'll still be getting Apple's Python.
You can change for your user scripts and sessions by munging your PATH in your .bash_profile or .profile, or system-wide in /etc/profile or /etc/paths, or for GUI apps and LaunchAgents in the appropriate environment.plist, etc. But you have to know which ones to change and why.
Also, other packages may expect /usr/local/bin to be after /usr/bin on the PATH.
There are plenty of people out there who can explain to you the difference between bash_profile and bashrc, bash_profile and profile, ~/.profile and /etc/profile, etc. But most of them are linux users who have no idea what an environment.plist is, how LaunchServices works, etc.—and they'll be mystified by the idea that anyone would have two system-wide installs of Python 2.7 in the first place.
Avoiding /usr/local helps, but not enough
The Python.org installers give you an option to leave /usr/local alone and install everything into the framework instead, letting you put /Library/Frameworks/Python.framework/Versions/2.7/bin on your PATH instead of /usr/local/bin.
Similarly, Homebrew lets you do a "keg-only" install, putting everything into /usr/local/Cellar/python/2.7.3/bin and not symlinking it into /usr/local/bin.
This solves a lot of the problems, but not all of them. You still have to get that path onto your PATH (and, when you forget what path was, you need to know how to find it again). And you still have name collisions, so you can still end up with "pip-2.7" installing packages that "ipython2.7" can't find.
Weird Apple libraries break stuff
Apple often installs specially-patched, bleeding-edge, or otherwise weird libraries, which they may test with their own Python, but not with third-party Pythons. This can cause problems like:
- On Snow Leopard 10.6, Apple's Tcl/Tk works with their Python, but with python.org's, IDLE and tkinter are broken. You have to follow the directions on python.org to install ActiveTcl.
- On Lion 10.7, Apple's libxml2 works with lxml built against their Python, but not against Homebrew Python. You have to follow the directions on the Homebrew wiki to install a keg-only libxml2 package, and figure out for yourself how to get lxml built against it.
Apple extras are missing
Apple's Python comes with a few extra batteries, notably PyObjC. Besides the fact that PyObjC is a huge package that can be a pain to install (especially if you're an early adopter of a new OS X version), there are scripts out there that expect to be able to just "import AppKit" or "import AddressBook". And when you asking someone why "import AddressBook" doesn't work, 99% of the time they'll go looking for a package with that name on PyPI, or tell you that you need to read the prerequisites for whatever package you're trying to use, which is not helpful.
Community support is unhelpful
There's a lot of great help out there for Python, from the official mailing list to sites like StackOverflow and SuperUser.
Almost none of these people can help you with running two system Python 2.7 versions in parallel. Linux and Windows users don't often do that. Many Mac users do, but only because they followed the same blog as you without really understanding what they were doing, and all they can say is, "Well, it worked for me."
Within the scipy community, and possibly certain other niches, things are different. There are a lot of Mac users, many of whom regularly do things like hacking on C extensions, and they all use python.org 2.7. If you plan to ask for more help among that community than in the general Python world, you may be better off using python.org 2.7. (But even there, honestly, I'd try it with Apple Python first, and only install another 2.7 if you run into problems. See Installing scipy, etc., with Apple's Python 2.7 and there's a good chance it will just work.)
Historically, Apple used to distribute very outdated, incomplete, and/or broken Python versions. The conventional wisdom was built in the pre-Leopard era where using Apple's Python was a fool's errand. Most of the people who really know what they were doing got things working in Apple's earlier systems, and haven't had any reason to learn why Apple's newer systems are different.
And even among those who know that Apple's doing things better, some don't trust Apple. How do we know OS X 10.9 won't come with Python 3.1 installed as python3? Or that 10.8.5 won't suddenly drop some of the key development files for 2.7, so you can't build C extensions anymore (as they did at one point in the old days)?
Finally, the people involving in packaging up Python for python.org are much more a part of the public community than the people involved in packaging it up as part of the OS X install.
So, why does everyone say to not use Apple's Python?
First, it's a whole lot easier to just say "Install the python.org version" than "If you don't have an Apple version 2.7, or you have an Apple 2.7.2 version but need the 2.7.3 fixes, or…"Historically, Apple used to distribute very outdated, incomplete, and/or broken Python versions. The conventional wisdom was built in the pre-Leopard era where using Apple's Python was a fool's errand. Most of the people who really know what they were doing got things working in Apple's earlier systems, and haven't had any reason to learn why Apple's newer systems are different.
And even among those who know that Apple's doing things better, some don't trust Apple. How do we know OS X 10.9 won't come with Python 3.1 installed as python3? Or that 10.8.5 won't suddenly drop some of the key development files for 2.7, so you can't build C extensions anymore (as they did at one point in the old days)?
Finally, the people involving in packaging up Python for python.org are much more a part of the public community than the people involved in packaging it up as part of the OS X install.
So why should I listen to you?
I see dozens of people on StackOverflow, mailing lists, in real life, etc. who don't understand how to manage two Python 2.7 installations, and are only doing it because "everyone says to do it", and can't get it to work.
Even if you know what you're doing, using Apple's Python is just much, much easier. While I set up a build machine with python.org 2.7.3 to run nightly tests and build py2app packages and so on, my personal dev boxes use Apple's 2.7.2, because it saves me a bit of time in setting up a new dev box, and a whole lot of time in avoiding regular hassles.
So, I think the blanket statement that most people should install another Python is wrong, at least in the 10.8 era. Certainly some people should. If you already know you need 2.7.3 or a py2app-capable standalone install or whatever, or you started with Apple's Python and then ran into a brick-wall problem with it, or your first source for help is the physics grad students down the hall rather than a site like StackOverflow, don't hesitate to install another 2.7. But otherwise, you may be a lot happier sticking with Apple's.
Shouldn't I just use 3.3 instead of 2.7 anyway?
Yes! There are plenty of good reasons some people need to stay on 2.x (see Python 2 or Python 3 on the official site for details—although it's more than 2 years out of date—and check PyPI to see if all the packages you need are 3.x-compatible). But if none of them apply to you, "Python 3.x is the present and the future of the language."
Plus, Python is designed to have multiple installations in parallel as long as they're not the same minor version, so most of the downsides in this post won't matter.
So, if you can use 3.3 instead of 2.7, go get it from python.org and stop worrying.
What about PyPy, IronPython, or Jython?
Well, for IronPython or Jython, if you need it, you probably already know you need it.
For PyPy, it's usually a tradeoff of "runs my code faster" vs. "doesn't have support for many libraries that I need". (As with 3.x, the situation is getting better every day, but may not be good enough yet for you.) And, even if performance or other features aren't important to you, it's a solid Python 2.7.3 implementation that can be installed in parallel with CPython 2.7.2 and happens to be faster to boot. But really, in most cases I can think of where you need 2.7 instead of 3.x, and can't use Apple's 2.7, you also can't use PyPy.
Still, if you can, go for it.
Add a comment