Psycopg2 and PostgreSQL 9.1 on Snow Leopard

Today I’ve had to install psycopg on my MacBook Pro running Mac OS X 10.6.8 (10K549) and I had some troubles doing that, so I’ll post this here just for the records.

To install PostgreSQL, i used the .dmg provided by postgresql web itself, as I’m not a big fan of fink or macports. And I downloaded psycopg from the project web. I’m not a big fan of Fink or MacPorts, so I didn’t use any of them to get any software, actually.

My first attempt was to install psycopg as usual, typing ‘$python setup.py install’, but I get this error:

That one was easy. I just added the location of pg_config at the end of the command. It looked like this: ‘$PATH=$PATH:/Library/PostgreSQL/9.1/bin python setup.py install’. Note that this is the path for a typical dmg installation of PostgreSQL on a Mac. It may differ to the one on your system.

And this is when things got complicated. The next error the system spit looked like this:

I then swith to easy_install, which is probably the easiest way to get python modules onto your system. Then, I typed: ‘$PATH=$PATH:/Library/PostgreSQL/9.1/bin/ sudo easy_install psycopg2′, but the same error appeared.

I also used pip, just in case ‘PATH=$PATH:/Library/PostgreSQL/9.1/bin pip install psycopg2′, but it resulted in the same error, again.

Finally, I assumed this should be something related to the architecture (well… that word appeared a couple of times in the error message… not a so-educated guess). I googled for a while and I found the answer in this post in StackOverflow.

Adding that env directive to the command, make it look like this: ‘$PATH=$PATH:/Library/PostgreSQL/9.1/bin sudo env ARCHFLAGS=”-arch i386 -arch x86_64″ pip install psycopg2′ and tada! It worked

I think this is something related to the development environment. Probably somehow related to XCode and iPhone development :(

Hope this helps.

About Pablo Casado

Clinical lecturer at BarcelonaTech - http://www.upc.edu
This entry was posted in Uncategorized. Bookmark the permalink.

Comments

7 Responses to Psycopg2 and PostgreSQL 9.1 on Snow Leopard

  1. I found the same thing, that Mac Ports and Fink were more trouble than they were worth and despite the warnings on the Psycopg website it was much easier to use easy install (especially when you’d done the hard work).

    • Yuki says:

      I found the same thing, that Mac Ports and Fink were more trouble than they were worth and diptese the warnings on the Psycopg website it was much easier to use easy install (especially when you’d done the hard work).

  2. Kerstin says:

    I need to say thank you so much for that work you have made in writing this posting. I am hoping the same perfect job from you down the road too.

  3. Ive heard postgreSQL is better for transaction processing than MySQL with InnoDB?

    Although I dont know why, how or by how much?

    I`d appreciate a simple English analysis.

  4. Chuck says:

    Hi,

    Thanks for posting this. Should the command to add to the path not have a leading $? Should it be this:

    PATH=$PATH:/Library/PostgreSQL/9.1/

    Thanks,
    Chuck

  5. I am grateful says:

    OMG!!! It works. THANK YOU.

  6. Chang says:

    Hi.. I’ve been fighting this with and just came aoscrs your post. i ran the command like you have it verbatim and get the follwoing error. Any ideas what I may be doing wrong?/usr/local/zend/apache2/build-1/libtool silent mode=compile gcc -prefer-pic -O2 -pipe -g -fno-common -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK -no-cpp-precomp -I/usr/local/pcre-7.8/include -I/usr/local/zend/apache2/include -I/usr/local/zend/apache2/include/apr-1 -I/usr/local/zend/apache2/include/apr-1 ”-arch -c -o mod_xsendfile.lo mod_xsendfile.c && touch mod_xsendfile.sloi686-apple-darwin10-gcc-4.2.1: ”-arch: No such file or directoryapxs:Error: Command failed with rc=65536

Leave a Reply