Posts tagged "snow leopard"

Snow Leopard’s Python 2.6 site-packages (and a psycopg2 issue)

THE ULTIMATE EDIT: I’ve got new instructions on how to conquer Symbol not found: \_PQbackendPID! Check them out here.


Maybe I’m a newb, maybe I’m not a newb. But I had a hard time installing Django (from scratch) on my new install of Mac OS X 10.6 Snow Leopard. It appears my issue was with the site-packages location. It’s got python26 installed by default, installed in

 /System/Library/Frameworks/Python.framework

So I ran my handy site-packages finding command:

 python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"

It gave me this path.

 /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages

So I linked Django to that directory. But when I tested my setup to see if it would load the Django modules, it wouldn’t. So I printed my pythonpath (going into the python shell and running import sys; print sys.path) and I found the only default site-packages directory in pythonpath.

 /Library/Python/2.6/site-packages

Once I linked Django there, it worked like a charm. Hope this saves you a 5-minute headache or something.


Update: I also ran into a bit of a tiff installing psycopg2 from source. I ran the following commands, which installed psycopg2 into the previously-listed System site-packages path:

 python setup.py build
 sudo python setup.py install

Rather, once I ran the easy install command (the setuptools for this seem to be included), my python setup found all the modules it needed for PostgreSQL integration.

 easy_install .

Again, hope this helps another 5-minute headache!


Another edit: there’s been some discussion in the comments about a problem with PostgreSQL/Python integration throwing errors in Snow Leopard. Namely, it’s the following error message:

 Symbol not found: _PQbackendPID

The general, scientific Internet consensus is that it’s due to a weird mixture of 32-bit plugins with a 64-bit process. Until more and more things become available as 64-bit, you’ll probably want to run Apple’s build of Python 2.6 as 32-bit for the time being. Here’s the terminal command to do just that.

 defaults write com.apple.versioner.python Prefer-32-Bit -bool yes

Not sure if that needs to be run with sudo, but there you have it. Thanks to @Mark and @John Simons for laying this out and explaining it.

Conquering Symbol not found: _PQbackendPID

Author’s note: this is in reference to a previous post, which didn’t quite involve this error, but evolved to a discussion on it anyway. It’s become a problem for me as well, and I didn’t want to run Python as 32-bit, so I’ve figured something out. Here it is.

I’ve found what may be the best solution for this, and it avoids MacPorts’ mumbo-jumbo (of which I’ve been trying to avoid as much as I can). It actually involves Homebrew, a new Mac package manager that bests MacPorts in a number of ways. It involves rolling up your sleeves and doing a little more work, but it adheres much more strictly to the Mac-like idea of not having to sudo for stuff as much as possible.

Anyway, install Homebrew, which I’ve done, to /usr/local, and use it to install python and postgresql (the directions for all this are at the github page for Homebrew). Then, download the source for psycopg2 — either recent build will work, I’ve used .11 and .13 — and unzip it somewhere, and then use the easy_install . command like before; this should use the new Python inside Homebrew’s setup (inside /usr/local/bin) instead. This worked for me like a charm, all without MacPorts (thank goodness)! Note that to get your shell to recognize the new Python over the old one, you’ll have to prioritize /usr/local/bin on your $PATH. You should probably already know how to do that.

Why does this work? From poking around the Intarwebs, as far as I can tell, it lays in how PostgreSQL is installed under Snow Leopard. I’ve tried so many things, and the only ones that seem to work are MacPorts’ build, and Homebrew’s build. I’ve tried building from source, using the installer from EnterpriseDB, etc. — and since Homebrew and MacPorts have specialized build strings (for architecture and what-not) for Leopard and (more specifically) Snow Leopard, this builds it in the right way for psycopg2 to access it — without the nasty _PQbackendPID error. Hope this helps!

I’m not sure how well this works in virtualenv — I haven’t gotten into using them yet, although I hear daily that I should. Anybody have a good learning resource on how to use virtualenv? If somebody lets me know, that’ll help me greatly.

Now I’m off to fix this, which I’ve done too many times to count:

PIL error