Search code examples
pythonpostgresqlpsycopg2

unable to install requirements txt


I am getting below mentioned error when i am trying to install dependencies ,

./psycopg/psycopg.h:35:10: fatal error: libpq-fe.h: No such file or directory 35 | #include <libpq-fe.h>

Depends: libpq5 (= 12.9-0ubuntu0.20.04.1) but 14.1-2.pgdg20.04+1 is to be installed


Solution

  • This error comes from the fact that you do not have the libpq-dev package installed on your Ubuntu system.

    You can solve this by either installing that package, or by using the psycopg2-binary package from pip instead of the psycopg2 package. The psycopg2-binary package contains a pre-compiled binary which means that you don't have to build the C extension when installing the dependencies of your app.

    So, plan of action:

    Either, you make sure to install the dependent packages on Ubuntu according to the psycopg2 documentation:

    sudo apt install python3-dev libpq-dev
    

    And then you should be able to run your requirements using pip install -r requirements.txt.

    The other option is to change the psycopg2 line in your requirements.txt file so that it says psycopg2-binary instead, and then you shouldn't have to install the libpq-dev package.

    You can read more about the differences between psycopg2 and psycopg2-binary in their slightly longer installation documentation