Error trying to install Postgres for python (psycopg2) Error trying to install Postgres for python (psycopg2) python python

Error trying to install Postgres for python (psycopg2)


The python-dev package is required for compilation of Python extensions written in C or C++, like psycopg2. If you're running a Debian-based distribution (e.g. Ubuntu), you can install python-dev by running

sudo apt install python-dev

or

sudo apt install python3-dev

depending on your python version (for example, sudo apt install python3.8-dev).

After that, proceed to install psycopg2 in your virtualenv environment as usual.


For Ubuntu 14.04, from Docker image python:3.4.3-slim this combination worked for me:

sudo apt-get updatesudo apt-get install -y build-essentialsudo apt-get install -y python3.4-devsudo apt-get install -y libpq-devpip3 install psycopg2

Note build-essential package. It was crucial in my case.


In my case (ubuntu 12.04 with python 2.7 and python 3.4 installed)

sudo apt-get install python3-dev 

was not enough. What did the trick was

sudo apt-get install python3.4-dev