Mar 29 2010
∞
How to build the pscyopg2 Python PostgreSQL interface on Mac OS X Snow Leopard
These instructions may work on earlier versions of OS X, but I’ve only tested on Snow Leopard.
A common problem for Python programmers using Mac OS X is how to install psycopg2, the standard Python interface for PostgreSQL.
If you Google for the instructions, you’ll get all kinds of advice, most of which involves using MacPorts or installing a complete server installation of PostgreSQL on your Mac.
I don’t want to do that.
I don’t want to run a database server on my local Mac. I want only the necessary PostgreSQL client libraries and I want to use the OS X native build system, not MacPorts.
It’s actually easy to do this. The instructions may look complicated, but it’s only because I’ve added a lot of explanation to them.
Step 1: Install the PostgreSQL client library
- Download the PostgreSQL source code from http://www.postgresql.org/ftp/source/. Don’t download Mac OS X binaries, as that would be a complete server installation.
- Un-tar the source code and
cdinto its directory. Then run:CFLAGS="-arch i386 -arch x86_64 -arch ppc" ./configure --with-openssl- This
CFLAGSsetting will get you a universal binary. Without it you would only get a 64-bit Intel binary (assuming you have a 64-bit Intel Mac), or a 32-bit Intel binary (if you have a 32-bit Intel Mac). We also include PowerPC support, for the unlikely event that you have a program that runs under Rosetta that needs to use the PostgreSQL libraries.
- This
- We are going install only the client parts of PostgreSQL. These instructions are based on the PostgreSQL manual, section 15.5.:
sudo make -C src/bin installsudo make -C src/include install- In my experience, the error about
utils/fmgroids.hcan be ignored.
- In my experience, the error about
sudo make -C src/interfaces installsudo make -C doc install
Step 2: Install Psycopg2
- Download and un-tar the Psycopg source code.
- Edit the psycopg2
setup.cfgfile. Add or update the following lines:have_ssl=1pg_config=/usr/local/pgsql/bin/pg_config
- Build and install it:
python setup.py buildsudo python setup.py install
- Test it:
$ python>>> import psycopg2>>> psycopg2.__version__'2.0.14 (dt dec ext pq3)'
Looks good!