Psycopg2 in a VirtualEnv

July 21, 2011

I tried to install psycopg2 in a VirtualEnv on debian, and got the following:

(perc360)drumcoder@drumcoder:~$ easy_install psycopg2
Searching for psycopg2
Reading <a href="http://pypi.python.org/simple/psycopg2/">http://pypi.python.org/simple/psycopg2/</a>
Reading <a href="http://initd.org/psycopg/">http://initd.org/psycopg/</a>
Reading <a href="http://initd.org/projects/psycopg2">http://initd.org/projects/psycopg2</a>
Best match: psycopg2 2.4.2
Downloading <a href="http://initd.org/psycopg/tarballs/PSYCOPG-2-4/psycopg2-2.4.2.tar.gz">http://initd.org/psycopg/tarballs/PSYCOPG-2-4/psycopg2-2.4.2.tar.gz</a>
Processing psycopg2-2.4.2.tar.gz
Running psycopg2-2.4.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-HzKn-1/psycopg2-2.4.2/egg-dist-tmp-H2K9j7
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 setup.py build_ext --pg-config /path/to/pg_config build ...

or with the pg_config option in 'setup.cfg'.
error: Setup script exited with 1

This is fixable by installing a couple more packages in debian:

# apt-get install libpq-dev python-dev

Once this is done, we can install the python postgres driver:

(perc360)drumcoder@drumcoder:~$ easy_install psycopg2
Searching for psycopg2
Reading <a href="http://pypi.python.org/simple/psycopg2/">http://pypi.python.org/simple/psycopg2/</a>
Reading <a href="http://initd.org/psycopg/">http://initd.org/psycopg/</a>
Reading <a href="http://initd.org/projects/psycopg2">http://initd.org/projects/psycopg2</a>
Best match: psycopg2 2.4.2
Downloading <a href="http://initd.org/psycopg/tarballs/PSYCOPG-2-4/psycopg2-2.4.2.tar.gz">http://initd.org/psycopg/tarballs/PSYCOPG-2-4/psycopg2-2.4.2.tar.gz</a>
Processing psycopg2-2.4.2.tar.gz
Running psycopg2-2.4.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-bAFryY/psycopg2-2.4.2/egg-dist-tmp-m5tdUY
no previously-included directories found matching 'doc/src/_build'
zip_safe flag not set; analyzing archive contents...
psycopg2.tests.types_basic: module references __file__
Adding psycopg2 2.4.2 to easy-install.pth file

Installed /home/tjs/.virtualenvs/perc360/lib/python2.5/site-packages/psycopg2-2.4.2-py2.5-linux-i686.egg
Processing dependencies for psycopg2
Finished processing dependencies for psycopg2

References