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:
Please add the directory containing pg_config to the PATH or specify the full executable path with the option: python setup.py build_ext --pg-config /path/to/pg_config build ... or with the pg_config option in 'setup.cfg'.
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:
Running psycopg2-2.4.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-LKNkhA/psycopg2-2.4.2/egg-dist-tmp-PbhT1X no previously-included directories found matching 'doc/src/_build' /usr/libexec/gcc/powerpc-apple-darwin10/4.2.1/as: assembler (/usr/bin/../libexec/gcc/darwin/ppc/as or /usr/bin/../local/libexec/gcc/darwin/ppc/as) for architecture ppc not installed Installed assemblers are: /usr/bin/../libexec/gcc/darwin/x86_64/as for architecture x86_64 /usr/bin/../libexec/gcc/darwin/i386/as for architecture i386 psycopg/psycopgmodule.c:1035: fatal error: error writing to -: Broken pipe compilation terminated.
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
Successfully installed psycopg2 Cleaning up...
I think this is something related to the development environment. Probably somehow related to XCode and iPhone development
Hope this helps.