How to clean up my Python Installation for a fresh start

Daniel Rhoden picture Daniel Rhoden · Dec 15, 2009 · Viewed 27.7k times · Source

I'm developing on Snow Leopard and going through the various "how tos" to get the MySQLdb package installed and working (uphill battle). Things are a mess and I'd like to regain confidence with a fresh, clean, as close to factory install of Python 2.6.

What folders should I clean out?

What should I run?

What symbolic links should I destroy or create?

Answer

Ned Deily picture Ned Deily · Dec 15, 2009

One thing you should not do is try to remove or change any of the Apple-supplied python files or links: they are in /usr/bin and /System/Library/Frameworks/Python.framework. These are part of OS X and managed by Apple. It is fine to clean up any unnecessary packages you have installed for that Python. They are in /Library/Python. If you installed a python.org Python and want to remove it, most of the files are in /Library/Frameworks/Python.framework. See here for complete instructions on how to remove them. And anything you installed into /usr/local is fair game.

Using virtualenvs is a fine idea but it's slightly less important on OS X where the concept of framework builds makes it easier to support multiple Python versions than on some other platforms.

The bigger issue, especially trying to use MySQL with Python, is getting all of the necessary non-Python libraries installed and built properly which is non-trivial given the variety of options available on OS X. For instance, depending on which Python instance and which OS X level running, you may need 32-bit or 64-bit or, possibly, both versions of things like the MySQL client libraries and the MySQLdb adapter. For that reason, I highly recommend using a complete solution from MacPorts. That way you have a good chance of getting all the right components built compatibly - and easily.

If necessary, install the base MacPorts as described on the MacPorts website then:

$ sudo port selfupdate
$ sudo port install py26-mysql 

and that will pull in and build everything you need and make it available in /opt/local/bin. There are also plenty of other ports available, for instance:

$ sudo port install py26-virtualenv