views:

125

answers:

3

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?

+1  A: 

My experience doing development on MacOSX is that the directories for libraries and installation tools are just different enough to cause a lot of problems that you end up having to fix by hand. Eventually, your computer becomes a sketchy wasteland of files and folders duplicated all over the place in an effort to solve these problems. A lot of hand-tuned configuration files, too. The thought of getting my environment set up again from scratch gives me the chills.

Then, when it's time to deploy, you've got to do it over again in reverse (unless you're deploying to an XServe, which is unlikely).

Learn from my mistake: set up a Linux VM and do your development there. At least, run your development "server" there, even if you edit the code files on your Mac.

Chris McCall
Can you recommend a free VM app to run Ubuntu?
Off Rhoden
http://www.virtualbox.org/Not my favorite (I prefer VMWare), but it's free.
Chris McCall
Although there's nothing wrong with using a Linux VM, MacPorts can provide nearly all of the advantages of using a Linux distribution's package manager by providing a self-contained and, usually, more up-to-date environment independent of the Apple-supplied OS X components. See my answer above.
Ned Deily
nearly all the advantages for considerably more effort? sign me up! :)
Chris McCall
If you already have an existing OS X system, it's hardly considerably more effort to install stuff from MacPorts. A couple of commands, wait a bit, and you're ready to go. And it's free, too. So consider yourself signed up!
Ned Deily
+3  A: 

Virtualenv might still be work for you. Install it, then create virtual python environments with the --no-site-packages option. This won't clean up your base system, but should allow you to develop in pretty good isolation from the base system.

Heikki Toivonen
+5  A: 

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/Frameworks/Library/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 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 py26-virtualenv
Ned Deily