Install psycopg2 on Ubuntu

Viewed 145692

I'm trying to get the python postgres client module installed on Ubuntu 12.04. The guidance is to do the following:

apt-get install python-psycopg2

However, apt says that the package can't be located.
I'm keen to install this through apt. Is this part of another package that I can install?

8 Answers

Use

sudo apt-get install python3-psycopg2

for Python3 )

This worked for me:

pip install psycopg2-binary

I updated my requirements.txt to have psycopg2==2.7.4 --no-binary=psycopg2 So that it build binaries on source

You should install the library using pip, but this requires multiple system dependencies:

sudo apt-get install libpq-dev python3-dev

Then you can run

pip install psycopg2

Debugging

If you are missing libpq-dev, you will get the error:

Error: pg_config executable not found.

If you are missing python3-dev, you will get the error:

fatal error: Python.h: No such file or directory

Related