Thursday, 4 July 2013

Django - Install Psycopg2 on Mac OS X - pg_config path issue AND lipo: can't open input file - Issues Resolved

In one of my recent Django based projects, I happened to use PostgreSQL as Database Backend. In order to connect the db and for other operations with PostgreSQL, python's psycopg2 module is pretty popular and readily used. Psycopg2 got easily installed on the Linux (Ubuntu) machine but I faced some issues when I tried to install it on my Mac OS X 10.6.7. After following several tips and reading several blog posts, I finally managed to find the actual working solution which resolved the issues of installing Psycopg2 on Mac OS X. I also noticed that many people were trying to find solution of the same issues which I faced. So I am writing their solutions in a single blog post in a descriptive and step-by-step manner. There are basically two most common issues which I also faced while installing psycopg2 on Mac OS X:


When I tried to install psycopg2 on Mac OS X and entered following command on my terminal:

>pip install psycopg2

I got an error that pg_config file's path is not specified. Following is the full trace:

Error: pg_config executable not found.

Please add the directory containing pg_config to the PATH

or specify the full executable path with the option:

    python build_ext --pg-config /path/to/pg_config build ...

or with the pg_config option in 'setup.cfg'.

Command python egg_info failed with error code 1 in /tmp/pip-build/psycopg2


Provided that some version of PostgreSQL is already installed, you will have to explicitly add the PATH of pg_config file in your PostgreSQL bin folder. In my case, the installation PATH for PostgreSQL is:


so to define the PATH of pg_config file, I entered following command in my terminal:
> PATH=$PATH:/opt/local/lib/postgresql91/bin/

After running this command, the pg_config path error while installing psycopg2 was resolved


While installing psycopg2 on my Mac OS X, the pip install psycopg2 command returned following error:

lipo: can't open input file: /var/tmp//ccTy5xAu.out (No such file or directory)

Full trace of the error is as follows:

psycopg/psycopgmodule.c:951: fatal error: error writing to -: Broken pipe

compilation terminated.

lipo: can't open input file: /var/tmp//ccTy5xAu.out (No such file or directory)

error: command 'gcc-4.2' failed with exit status 1


After a googling a bit, and trying several recipes, the solution that worked for me was the following command which overrides the ARCHFLAGS architecture settings:

sudo env ARCHFLAGS="-arch i386 -arch x86_64" pip install psycopg2

This command finally installed psycopg2 on my Mac OS X without any issues.