DevOps | Cloud | Analytics | Open Source | Programming





How To Fix - "Error: Libpq-fe.h: No Such File or Directory" ?



In this post, we will see How To Fix "Error: libpq-fe.h: No Such File or Directory". There can be various formats of the error depending on the context of use. Couple of those are shown below -


error: libpq-fe.h: No such file or directory


Can't find the 'libpq-fe.h header


psycopg2 fatal error libpq-fe.h no such file or directory


cannot open include file 'libpq-fe.h' no such file or directory

This issue occurs while installing postgresql or psycopg2 if the steps are not followed properly.  

  • Did you install pyscopg2 correctly ? Note that - it is a C wrapper around the libpq postgreSQL client library. And hence there are few things that you need to take care of. Follow the below steps if not done already.
  To solve the error, use the below -  

Option 1 : General Steps

 

  • Python header files - These are needed for pycopg2. So install these by installing the the package - python-dev or python3-dev as per the python version.

sudo apt-get install python-dev  <- for python 2.7

sudo apt-get install python3.5-dev <- python 3.5

sudo apt-get install python3.9-dev <- python 3.9

Note : While doing this step, if you see an error - "Python.h: No such file or directory", the fix is explained here - How To Fix – fatal error: Python.h: No such file or directory ?  

  • libpq header files - These are also needed for psycopg2. So install these by installing the package libpq-dev.

sudo apt-get install libpq-dev

 

  • pg_config -  It is installed by the libpq-dev package. But it might get missed from being added to the PATH. Get the path . Generally it is - /usr/lib/postgresql/X.Y/bin/. And then add it to the PATH.

$ export PATH=/usr/lib/postgresql/X.Y/bin/:$PATH

 

  • Assuming you followed the above steps, run the below -

$ pip install psycopg2

 

Option 2: For Ubuntu

Use below -


sudo apt install libpq-dev

 

Option 3:

Use below snippets


sudo yum install postgresql-devel

yum install python-devel postgresql-devel

 

Option 4 : Using already installed libpq-fe.h correctly

There is possibility that libpq-fe.h is already in the system. But it is not being correctly pointed at. Follow below steps for that.

  • Check libpq version and info

brew info libpq

  • Locate libpq-fe.h

yum install mlocate 

sudo updateb 

locate libpq-fe.h

 

  • Update ~/.bash_profile. pg_config is installed by the libpq-dev package. But it might get missed from being added to the PATH. Get the path . Generally it is - /usr/lib/postgresql/X.Y/bin/. And then add it to the PATH.

export PATH=/usr/lib/postgresql/X.Y/bin/:$PATH

OR

export PATH=/usr/pgsql-10/bin/:$PATH

 

  • As a next step just install psycopg2 or whatever you have being doing. That should work.
   

Option 5 : For Mac

 


brew install libpq


brew link --force libpq


gem install pg

  Hope this helps to solve the error.  

Other Interesting Reads -

   


libpq-fe.h no such file or directory ,libpq-fe.h no such file or directory psycopg2 ,fatal error libpq-fe.h no such file or directory centos ,cannot open include file 'libpq-fe.h' no such file or directory ,psycopg libpq-fe.h no such file or directory ,ruby fatal error libpq-fe.h no such file or directory ,python psycopg2 libpq-fe.h no such file or directory ,r fatal error libpq-fe.h no such file or directory ,libpq-fe.h no such file or directory centos ,libpq-fe.h no such file or directory centos 7 , ,error libpq-fe.h no such file or directory ,psycopg2 fatal error libpq-fe.h no such file or directory ,fatal error libpq-fe.h no such file or directory centos ,psycopg fatal error libpq-fe.h no such file or directory ,ruby fatal error libpq-fe.h no such file or directory ,r fatal error libpq-fe.h no such file or directory , , ,libpq-fe.h no such file or directory centos 7 ,libpq-fe.h no such file or directory psycopg2 ,libpq-fe h no such file or directory windows ,libpq-dev ,pip libpq-fe.h: no such file or directory ,can't find the 'libpq-fe.h header ,fatal error: libpq-fe.h: no such file or directory ubuntu ,libpq-fe.h psycopg2 , , ,libpq-fe.h no such file or directory centos 7 ,fatal error: libpq-fe.h: no such file or directory ubuntu ,can't find the 'libpq-fe.h header ,fatal error libpq-fe.h no such file or directory psycopg2 ,libpq-dev ,configure: error: cannot find libpq-fe h please specify correct postgresql installation path ,libpq-fe.h psycopg2 ,libpq-fe h file not found mac , , , , ,libpq-fe.h ,libpq-fe.h no such file ,libpq-fe.h psycopg2 ,libpq-fe.h centos ,libpq-fe.h debian ,libpq-fe.h windows ,libpq-fe.h install ubuntu ,libpq-fe.h brew ,libpq-fe.h fedora ,libpq-fe.h alpine ,libpq-fe.h apt ,arch libpq-fe.h ,can't find the 'libpq-fe.h header alpine ,alpine cannot find libpq-fe.h ,brew libpq-fe.h ,bundle libpq-fe.h ,bundle install libpq-fe.h ,libpq-fe.h centos 8 ,libpq-fe.h centos 6 ,#include libpq-fe.h ^ compilation terminated ,cannot find libpq-fe.h ,cannot find libpq-fe.h php ,can't find libpq-fe.h in /usr/include ,can't find the 'libpq-fe.h header windows ,libpq-fe.h download ,postgresql libpq-fe.h download ,debian install libpq-fe.h ,debian stretch libpq-fe.h ,docker cannot find libpq-fe.h ,libpq-fe.h' file not found mac ,libpq-fe.h file not found ,libpq-fe.h functions ,libpq-fe.h github ,libpq-fe.h gem install pg ,gcc libpq-fe.h ,how to get libpq-fe.h ,libpq-fe.h header ,can't find the 'libpq-fe.h header ubuntu 20.04 ,can't find the 'libpq-fe.h header centos 8 ,opensuse can't find the 'libpq-fe.h header ,how to download libpq-fe.h ,libpq-fe.h install ,libpq-fe.h yum install ,#include libpq-fe.h psycopg2 ,pip install psycopg2 libpq-fe.h ,/usr/include/postgresql/libpq-fe.h ,libpq-fe.h missing ,libpq-fe.h missing linux ,libpq-fe.h not found ,libpq-fe.h postgresql ,libpq-fe.h pip ,psycopg libpq-fe.h ,python libpq-fe.h ,rails postgres libpq-fe.h ,r postgres libpq-fe.h ,libpq-fe.h ubuntu ,unable to find libpq-fe.h ,ubuntu cannot find libpq-fe.h , ,/usr/include/libpq-fe.h ,libpq-fe.h windows download ,libpq-fe.h what is ,libpq-fe.h no such file or directory psycopg2 ,libpq-fe.h no such file or directory centos ,libpq-fe.h no such file or directory windows ,libpq-fe.h no such file or directory r ,libpq-fe.h no such file or directory c++ ,libpq-fe.h no such file or directory redhat ,python libpq-fe.h no such file or directory ,python psycopg2 libpq-fe.h no such file or directory ,error libpq-fe.h no such file or directory ,fatal error libpq-fe.h no such file or directory #include libpq-fe.h ,fatal error postgresql/libpq-fe.h no such file or directory ,libpq-fe.h no such file or directory ,cannot open include file 'libpq-fe.h' no such file or directory ,fatal error libpq-fe.h no such file or directory psycopg2 ,fatal error libpq-fe.h no such file or directory centos ,psycopg fatal error libpq-fe.h no such file or directory ,ruby fatal error libpq-fe.h no such file or directory ,r fatal error libpq-fe.h no such file or directory ,fatal error libpq-fe.h no such file or directory ,configure error cannot find libpq-fe.h ,libpq-fe.h no such file or directory #include libpq-fe.h ,postgresql/libpq-fe.h no such file or directory ,can't find the 'libpq-fe.h header ubuntu ,libpq-fe.h no such file or directory ubuntu ,psycopg2 fatal error libpq-fe.h ,libpq.a ,pip install psycopg2 error libpq-fe.h ,libpq postgresql ,centos 7 libpq-fe.h ,can't find the 'libpq-fe.h header centos ,centos cannot find libpq-fe.h ,libpq-fe.h centos 7 ,can't find the 'libpq-fe.h header centos 7 ,libpq-dev for centos , , ,#include libpq-fe.h ^ compilation terminated ,configure error cannot find libpq-fe.h ,configure error could not find libpq-fe.h ,configure error could not find libpq-fe.h header ,configure error header file libpq-fe.h is required ,error 'libpq-fe.h' file not found ,error cannot find libpq-fe.h ,error libpq-fe.h no such file or directory ,fatal error 'libpq-fe.h' file not found ,fatal error libpq-fe.h ,fatal error libpq-fe.h no such file or directory #include libpq-fe.h ,fatal error libpq-fe.h no such file or directory centos ,fatal error postgresql/libpq-fe.h ,fatal error postgresql/libpq-fe.h no such file or directory ,libpq-fe.h error eclipse ,libpq-fe.h error error ,libpq-fe.h error example ,libpq-fe.h error exception ,libpq-fe.h error git ,libpq-fe.h error github ,libpq-fe.h error java ,libpq-fe.h error javascript ,libpq-fe.h error juniper ,libpq-fe.h error jupyter notebook ,libpq-fe.h error keras ,libpq-fe.h error kernel ,libpq-fe.h error key ,libpq-fe.h error kubernetes ,libpq-fe.h error linux ,libpq-fe.h error list ,libpq-fe.h error loading ,libpq-fe.h error log ,libpq-fe.h error query ,libpq-fe.h error queue ,libpq-fe.h error timeout ,libpq-fe.h error windows ,libpq-fe.h error windows 10 ,libpq-fe.h error xcode ,libpq-fe.h error xml ,libpq-fe.h error xpath ,libpq-fe.h error yaml ,libpq-fe.h error youtube ,libpq-fe.h error zero ,libpq-fe.h error zerodha ,libpq-fe.h error zip ,libpq-fe.h error zoom ,libpq-fe.h error zoominfo ,libpq-fe.h not found ,pip install psycopg2 error libpq-fe.h ,psycopg fatal error libpq-fe.h ,psycopg2 fatal error libpq-fe.h ,#include libpq-fe.h ,#include libpq-fe.h ^ compilation terminated ,#include libpq-fe.h psycopg2 ,alpine cannot find libpq-fe.h ,alpine libpq-fe.h ,arch libpq-fe.h ,brew libpq-fe.h ,bundle install libpq-fe.h ,bundle libpq-fe.h ,can't find libpq-fe.h in /usr/include ,can't find the 'libpq-fe.h ,can't find the 'libpq-fe.h header ,can't find the 'libpq-fe.h header alpine ,can't find the 'libpq-fe.h header centos 8 ,can't find the 'libpq-fe.h header mac ,can't find the 'libpq-fe.h header osx ,can't find the 'libpq-fe.h header ubuntu 20.04 ,can't find the 'libpq-fe.h header windows ,cannot find libpq-fe.h ,cannot find libpq-fe.h php ,centos 7 libpq-fe.h ,centos libpq-fe.h ,could not find libpq-fe.h ,debian install libpq-fe.h ,debian libpq-fe.h ,debian stretch libpq-fe.h ,docker cannot find libpq-fe.h ,download libpq-fe.h ,error 'libpq-fe.h' file not found ,example libpq-fe.h ,fatal error libpq-fe.h ,fatal error postgresql/libpq-fe.h ,find header checking for libpq-fe.h ,gcc libpq-fe.h ,gem pg libpq-fe.h ,header file libpq-fe.h is required ,how to download libpq-fe.h ,how to get libpq-fe.h ,how to install libpq-fe.h in ubuntu ,instalar libpq-fe.h ,libpq-fe.h ,libpq-fe.h alpine ,libpq-fe.h apt ,libpq-fe.h brew ,libpq-fe.h c ,libpq-fe.h centos ,libpq-fe.h centos 6 ,libpq-fe.h centos 7 ,libpq-fe.h centos 8 ,libpq-fe.h debian ,libpq-fe.h download ,libpq-fe.h fedora ,libpq-fe.h functions ,libpq-fe.h gem install pg ,libpq-fe.h github ,libpq-fe.h header ,libpq-fe.h install ,libpq-fe.h install ubuntu ,libpq-fe.h missing ,libpq-fe.h missing linux ,libpq-fe.h no such file ,libpq-fe.h not found ,libpq-fe.h pip ,libpq-fe.h postgresql ,libpq-fe.h psycopg2 ,libpq-fe.h r ,libpq-fe.h rpm ,libpq-fe.h ubuntu ,libpq-fe.h visual studio ,libpq-fe.h what is ,libpq-fe.h windows ,libpq-fe.h windows download ,libpq-fe.h yum install , libpq-fe.h' file not found mac ,missing libpq-fe.h ,no file libpq-fe.h in /usr/local/include ,no such file libpq-fe.h ,opensuse can't find the 'libpq-fe.h header ,pip install psycopg2 libpq-fe.h ,postgresql libpq-fe.h download ,psycopg fatal error libpq-fe.h ,psycopg libpq-fe.h ,psycopg2 fatal error libpq-fe.h ,psycopg2 libpq-fe.h ,python libpq-fe.h ,r postgres libpq-fe.h ,rails can't find the 'libpq-fe.h header ,rails postgres libpq-fe.h ,rhel 7 libpq-fe.h ,rpostgresql libpq-fe.h ,ubuntu cannot find libpq-fe.h ,ubuntu libpq-fe.h ,unable to find libpq-fe.h ,what is libpq-fe.h ,where is libpq-fe.h ,windows libpq-fe.h ,yum install libpq-fe.h ,yum libpq-fe.h , ,


libpq-fe.h error ,error 'libpq-fe.h' file not found ,fatal error libpq-fe.h ,psycopg2 fatal error libpq-fe.h ,psycopg fatal error libpq-fe.h ,fatal error postgresql/libpq-fe.h ,error libpq-fe.h no such file or directory ,fatal error libpq-fe.h no such file or directory #include libpq-fe.h ,#include libpq-fe.h ^ compilation terminated ,fatal error postgresql/libpq-fe.h no such file or directory ,error cannot find libpq-fe.h ,configure error cannot find libpq-fe.h ,configure error header file libpq-fe.h is required ,pip install psycopg2 error libpq-fe.h ,fatal error 'libpq-fe.h' file not found mac ,fatal error libpq-fe.h no such file or directory centos ,fatal error 'libpq-fe.h' file not found