Фатальная ошибка libpq fe h нет такого файла или каталога
Hello, I'm trying to install RPostgres in the a Docker container. However, the compilation fails because the libpq-fe.h file can't be found even though it exists:
This is the error message:
This is the Docker image I'm building:
I set the following environment variables inside the container:
I can install RPostgreSQL without any problems so I don't think it's an issue with libpq-dev.
This is the output from pg_config:
BINDIR = /usr/lib/postgresql/14/bin
DOCDIR = /usr/share/doc/postgresql-doc-14
HTMLDIR = /usr/share/doc/postgresql-doc-14
INCLUDEDIR = /usr/include/postgresql
PKGINCLUDEDIR = /usr/include/postgresql
INCLUDEDIR-SERVER = /usr/include/postgresql/14/server
LIBDIR = /usr/lib/x86_64-linux-gnu
PKGLIBDIR = /usr/lib/postgresql/14/lib
LOCALEDIR = /usr/share/locale
MANDIR = /usr/share/postgresql/14/man
SHAREDIR = /usr/share/postgresql/14
SYSCONFDIR = /etc/postgresql-common
PGXS = /usr/lib/postgresql/14/lib/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--build=x86_64-linux-gnu' '--prefix=/usr' '--includedir=$/include' '--mandir=$/share/man' '--infodir=$/share/info' '--sysconfdir=/etc' '--localstatedir=/var' '--disable-option-checking' '--disable-silent-rules' '--libdir=$/lib/x86_64-linux-gnu' '--runstatedir=/run' '--disable-maintainer-mode' '--disable-dependency-tracking' '--with-icu' '--with-tcl' '--with-perl' '--with-python' '--with-pam' '--with-openssl' '--with-libxml' '--with-libxslt' 'PYTHON=/usr/bin/python3' '--mandir=/usr/share/postgresql/14/man' '--docdir=/usr/share/doc/postgresql-doc-14' '--sysconfdir=/etc/postgresql-common' '--datarootdir=/usr/share/' '--datadir=/usr/share/postgresql/14' '--bindir=/usr/lib/postgresql/14/bin' '--libdir=/usr/lib/x86_64-linux-gnu/' '--libexecdir=/usr/lib/postgresql/' '--includedir=/usr/include/postgresql/' '--with-extra-version= (Debian 14.0-1)' '--enable-nls' '--enable-thread-safety' '--enable-tap-tests' '--enable-debug' '--enable-dtrace' '--disable-rpath' '--with-uuid=e2fs' '--with-gnu-ld' '--with-lz4' '--with-pgport=5432' '--with-system-tzdata=/usr/share/zoneinfo' '--with-llvm' 'LLVM_CONFIG=/usr/bin/llvm-config-11' 'CLANG=/usr/bin/clang-11' '--with-systemd' '--with-selinux' 'AWK=mawk' 'MKDIR_P=/bin/mkdir -p' 'PROVE=/usr/bin/prove' 'TAR=/bin/tar' 'XSLTPROC=xsltproc --nonet' 'CFLAGS=-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer' 'LDFLAGS=-Wl,-z,relro -Wl,-z,now' '--with-gssapi' '--with-ldap' 'build_alias=x86_64-linux-gnu' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' 'CXXFLAGS=-g -O2 -fstack-protector-strong -Wformat -Werror=format-security'
CC = gcc
CPPFLAGS = -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2
CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -g -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer
CFLAGS_SL = -fPIC
LDFLAGS = -Wl,-z,relro -Wl,-z,now -L/usr/lib/llvm-11/lib -Wl,--as-needed
LDFLAGS_EX =
LDFLAGS_SL =
LIBS = -lpgcommon -lpgport -lselinux -llz4 -lxslt -lxml2 -lpam -lssl -lcrypto -lgssapi_krb5 -lz -lreadline -lpthread -lrt -ldl -lm
VERSION = PostgreSQL 14.0 (Debian 14.0-1)
I am using the Ruby on Rails 3.1 pre version. I like to use PostgreSQL, but the problem is installing the pg gem. It gives me the following error:
How do I solve this problem?
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 –
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 3:
Use below snippets
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.
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.
- 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.
- Assuming you followed the above steps, run the below –
Option 2: For Ubuntu
45 Answers 45
It looks like in Ubuntu that header is part of the libpq-dev package (at least in the following Ubuntu versions: 11.04 (Natty Narwhal), 10.04 (Lucid Lynx), 11.10 (Oneiric Ocelot), 12.04 (Precise Pangolin), 14.04 (Trusty Tahr) and 18.04 (Bionic Beaver)):
So try installing libpq-dev or its equivalent for your OS:
- For Ubuntu/Debian systems: sudo apt-get install libpq-dev
- On Red Hat Linux (RHEL) systems: yum install postgresql-devel
- For Mac Homebrew: brew install postgresql
- For Mac MacPorts PostgreSQL: gem install pg -- --with-pg-config=/opt/local/lib/postgresql[version number]/bin/pg_config
- For OpenSuse: zypper in postgresql-devel
- For ArchLinux: pacman -S postgresql-libs
didn't work for me on ubuntu 11.04 durrantm@castleLinux2011:~/Dropbox_not_syncd/webs/3/linker$ gem install libpq-dev ERROR: Could not find a valid gem 'libpq-dev' (>= 0) in any repository durrantm@castleLinux2011:~/Dropbox_not_syncd/webs/3/linker$
If you then are required to have a javascript library installed. gem install 'execjs' and gem install 'therubyracer'
While I executed the command : sudo apt-get install libpq-dev, I get a response - "Unable to locate package". So I execute sudo apt-get update, then executed "sudo apt-get install libpq-dev". Finally it successfully installed.
This worked for me, I already had installed Postgres, and I just needed to execute sudo apt-get install libpq-dev then bundle install and the error disappeared. Thanks
On macOS (previously Mac OS X and OS X), use Homebrew to install the proper headers:
and then running
Alternatively, instead of installing the whole postgresql , you can brew install libpq and export the correct PATH and PKG_CONFIG_PATH as explained in the 'Caveats' section
For me after run brew install postgressql i run ARCHFLAGS="-arch x86_64" gem install pg and works fine.
@RicardoSaporta libpqxx installs postgresql as dependency, so it is essentially the same as brew install postgresql
Instead of installing the whole postgresql , you can brew install libpq and export the correct PATH and PKG_CONFIG_PATH as explained in the 'Caveats' section.
I had also tried doing gem install libpq-dev , but I received this error:
However I found that installing with sudo apt-get (which I try to avoid using with Ruby on Rails) worked, i.e.
then I was able to do
Right, the Ruby pg gem wraps the usual PostgreSQL C libraries that come with the Ubuntu/Debian/. libpq-dev package.
I could solve this in another way. I didn't find the library on my system. Thus I installed it using an app from PostgreSQL main website. In my case (OS X) I found the file under /Library/PostgreSQL/9.1/include/ once the installation was over. You may also have the file somewhere else depending on your system if you already have PostgreSQL installed.
Thanks to this link on how to add an additional path for gem installation, I could point the gem to the lib with this command:
After that, it works, because it now knows where to find the missing library. Just replace the path with the right location for your libpq-fe.h
Sorry for this text. Your post does not have much context to explain the code sections; please explain your scenario more clearly.
Option 5 : For Mac
Hope this helps to solve the error.
Other Interesting Reads –
How to Send Large Messages in Kafka ?
Fix Spark Error – “org.apache.spark.SparkException: Failed to get broadcast_0_piece0 of broadcast_0”
How to Handle Bad or Corrupt records in Apache Spark ?
How to use Broadcast Variable in Spark ?
Best Practices for Dependency Problem in Spark
Sample Code – Spark Structured Streaming vs Spark Streaming
Sample Code for PySpark Cassandra Application
How to Enable UTF-8 in Python ?
How to log an error in Python ?
Sample Python Code To Read & Write Various File Formats (JSON, XML, CSV, Text)
How to Handle Errors and Exceptions in Python ?
How to Handle Bad or Corrupt records in Apache Spark ?
How To Fix – Partitions Being Revoked and Reassigned issue in Kafka ?
What Are The Most Important Metrics to Monitor in Kafka ?
How To Connect Local Python to Kafka on AWS EC2 ?
Tutorials
Interview Series
Popular Posts
Do Not Copy Information
Я использую версию Ruby on Rails 3.1 pre. Мне нравится использовать PostgreSQL, но проблема заключается в установке pg камень. Это дает мне следующую ошибку:
Как решить эту проблему?
похоже, что в Ubuntu этот заголовок является частью libpq-dev пакета (по крайней мере, в следующих версиях Ubuntu: 11.04 (Натти Нарвал), 10.04 (Lucid Lynx),11.10 (Онейроидного Оцелота), 12.04 (Точный Панголин), 14.04 (надежный Тар) и 18.04 (Bionic Beaver)):
так попробуйте установить libpq-dev или его эквивалент для вашего ОС:
- для систем Ubuntu: sudo apt-get install libpq-dev
- On Red Hat Linux (RHEL) системы: yum install postgresql-devel
- Для Mac доморощенного: brew install postgresql
- Для Mac MacPorts PostgreSQL: gem install pg -- --with-pg-config=/opt/local/lib/postgresql[version number]/bin/pg_config
- на в openSUSE: zypper in postgresql-devel
- на ArchLinux: pacman -S postgresql-libs
On macOS (ранее Mac OS X и OS X), используйте доморощенного установить правильные заголовки:
и потом работает
Я также пытался сделать gem install libpq-dev , но я получил эту ошибку:
однако я обнаружил, что установка с sudo apt-get (который я стараюсь избегать использования с Ruby on Rails) работал, т. е.
тогда я смог сделать
я мог бы решить это по-другому. Я не нашел библиотеку в своей системе. Таким образом, я установил его с помощью приложения с основного веб-сайта PostgreSQL. В моем случае (OS X) я нашел файл под /Library/PostgreSQL/9.1/include/ после завершения установки. Вы также можете иметь файл где-то еще в зависимости от вашей системы, если у вас уже установлен PostgreSQL.
благодаря этой ссылке как добавить дополнительный путь для установки gem, я мог бы указать камень на lib с этим команда:
после этого он работает, потому что теперь он знает, где найти недостающую библиотеку. Просто замените путь правильным местоположением для вашего libpq-fe.h
не удается найти libpq-fe.H заголовка
у меня был успех на CentOS 7.0.1406 выполнение следующих команд:
как вариант, вы можете настроить bundler всегда устанавливать pg С этими параметрами (полезно для запуска bundler в средах развертывания),
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
- 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.
- As a next step just install psycopg2 or whatever you have being doing. That should work.
16 Answers 16
I tried to do that on Ubuntu 14.04 but it gave me this: " libpq-dev : Depends: libpq5 (= 9.3.4-1) but 9.3.10-0ubuntu0.14.04 is to be installed "
PostgreSQL version is: psql --version: psql (PostgreSQL) 9.3.10. PostgreSQL 9.3.10 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2, 64-bit
Brilliant! The application I was compiling also needed the path to libpq-fe.h to be specified explicitly, with --with-cflags=-I/usr/include/postgresql , in case anyone else encounters the same.
This was what ended up working for me, or at least the Mac version of it, which is brew install libpq . I then also had to brew link --force libpq to get the gem install pg to finish successfully.
Depending on your environment:
- Mac: brew install postgresql
- Ubuntu: sudo apt-get install libpq-dev
- RHEL: yum install postgresql-devel
Then run gem install pg again
I tried to do that on Ubuntu 14.04 but it gave me this: " libpq-dev : Depends: libpq5 (= 9.3.4-1) but 9.3.10-0ubuntu0.14.04 is to be installed "
But then when I try to install libpq5, it says "libpq5 is already the newest version." Same for PostgreSQL
PostgreSQL version is: psql --version: psql (PostgreSQL) 9.3.10. PostgreSQL 9.3.10 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2, 64-bit
- brew install postgresql
- gem install pg
- bundle install
On Fedora/RHEL systems this did the trick:
$ sudo apt-get install libpq-dev
In my case I was putting the directory path wrong. So:
From: gcc -o lib_version lib_version.c -I/usr/include/postgresql -lpq -std=c99
To: gcc -o lib_version lib_version.c -I /usr/include/postgresql -lpq -std=c99
For Alpine Linux, you can add libpq-fe.h with:
For Amazon Linux (AWS):
then run your command again
On Mac OS X run like this:
***/path/to/pg_config*** is path to pg_config
I had this issue with a Jenkins server on Amazon AMI.
Then depending on which version you need you can install the required lib
Then you can just install the corresponding version, in my case for version 9.4:
This was happening me using capistrano while deploying my app in a centos7 distro. Apparently gem is requiring some header files which can be resolved installing the right development package.
I fixed it by running sudo yum search postgres | grep devel and found the right package for my postgres installation which was 10.
Читайте также: