Psycopg on Mac OS 10.8 with Python 2.7 and Postgresql 9.2

I don't have time for a full tutorial, but here is how I managed, after weeks of trying without luck, to get Psycopg2 to work with Python 2.7.3 and PostgreSQL 9.2 on Mac OS 10.8, Mountain Lion.

The problem I was having, after installing Psycopg using python install was related to this error when running import psycopg2 from a Python shell. Symbol not found: _PQbackendPID.

This fixed it:

  1. You'll need XCode from the App Store and the Command Line Tools (Google it if this sounds like gibberish).
  2. Follow the instructions about exporting your path here: This will make your Postgresql 9.2 the default. You can check if it already is by typing which psql in a Terminal window.
  3. Create a Universal libpq.dylib following instructions here: Copy the new file to wherever your Postgresql is. In my case it was /Library/PostgreSQL/9.2/lib. These instructions solved the 64/32 bit architecture problem. (This crucial piece of info was burried in Google and took quite a while to find. All other solutions suggested running Python in 32 bit mode, which didn't work).
  4. Modify the psycopg2 setup.cfg file following these instructions (only the last part, right after "Change setup.cfg so it looks like the following:"):
  5. Create the simlinks mentioned in the comments here in order to fix a new problem with SSL and Crypto libraries:
  6. Now build psycopg2 using "python install".
  7. You should be able to import psycopg2 from a Python shell or from IDLE (I actually did it for EPD free).

Many, many thanks to each of the four sources cited in steps 2-6. You did all the work. All I needed to do was find which instructions to follow.

I hope this helps others struggling with this issue.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.