提问人:demonchand 提问时间:5/18/2011 最后编辑:Cadoizdemonchand 更新时间:4/5/2023 访问量:419641
尝试安装 pg gem 时找不到“libpq-fe.h 标头”
Can't find the 'libpq-fe.h header when trying to install pg gem
问:
我正在使用 Ruby on Rails 3.1 预版本。我喜欢使用 PostgreSQL,但问题是安装 gem。它给了我以下错误:pg
$ gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/home/u/.rvm/rubies/ruby-1.9.2-p0/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/home/u/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
--with-pg
--without-pg
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
Gem files will remain installed in /home/u/.rvm/gems/ruby-1.9.2-p0/gems/pg-0.11.0 for inspection.
Results logged to /home/u/.rvm/gems/ruby-1.9.2-p0/gems/pg-0.11.0/ext/gem_make.out
如何解决这个问题?
答:
在 Ubuntu 中,标头似乎是 libpq-dev
包的一部分(至少在以下 Ubuntu 版本中:11.04 (Natty Narwhal)、10.04 (Lucid Lynx)、11.10 (Oneiric Ocelot)、12.04 (Precise Pangolin)、14.04 (Trusty Tahr) 和 18.04 (Bionic Beaver)):
...
/usr/include/postgresql/libpq-fe.h
...
因此,请尝试为您的操作系统安装或其等效项:libpq-dev
- 对于 Ubuntu/Debian 系统:
sudo apt-get install libpq-dev
- 在 Red Hat Linux (RHEL) 系统上:
yum install postgresql-devel
- 对于 Mac Homebrew:
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
评论
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$
apt-get install postgres-server-dev-{pg.version}
sudo apt-get install libpq-dev
bundle install
就我而言,它是软件包(我在 Ubuntu 11.04 (Natty Narwhal),64 位)。postgresql-server-dev-8.4
我可以用另一种方式解决这个问题。我在系统上找不到该库。因此,我使用 PostgreSQL 主网站上的应用程序安装了它。就我而言(OS X),安装结束后,我找到了该文件。如果您已经安装了 PostgreSQL,您也可以将文件放在其他地方,具体取决于您的系统。/Library/PostgreSQL/9.1/include/
多亏了这个关于如何为 gem 安装添加额外路径的链接,我可以使用以下命令将 gem 指向库:
export CONFIGURE_ARGS="with-pg-include=/Library/PostgreSQL/9.1/include/"
gem install pg
在那之后,它就可以工作了,因为它现在知道在哪里可以找到丢失的库。只需将路径替换为 libpq-fe.h 的正确位置即可
评论
export CONFIGURE_ARGS="with-pg-include=/usr/local/Cellar/postgresql/9.3.1/include/"
pg_*
ln -s /usr/pgsql-9.3/bin/p* /usr/local/bin
yum install http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-redhat93-9.3-1.noarch.rpm && yum install postgresql93 postgresql93-contrib postgresql93-server postgresql93-devel
gem install pg -- with-pg-include=/Library/PostgreSQL/9.1/include/
export CONFIGURE_ARGS="with-pg-config=/path/to/postgres/bin/pg_config"
pg_config
我也试过做,但我收到这个错误:gem install libpq-dev
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
但是,我发现安装(我尽量避免与Ruby on Rails一起使用)是有效的,即sudo apt-get
sudo apt-get install libpq-dev
# or
apt-get install postgres-server-dev-{pg.version}
# for postgresql 9.4 on Ubuntu 14.04
然后我能够做到
gem install pg
没有问题。
评论
libpq-dev
我通过rvm重新安装Ruby修复了相同的错误:
rvm reinstall 1.9.3
评论
我解决了安装“postgresql-common”包的问题。此软件包提供了二进制文件,这很可能是您缺少的。pg_config
对于 CentOS 6.4,
yum install postgresql-devel
gem install pg
效果很好!
评论
sudo port install postgresql-devel
对于任何基于 Debian 的发行版(包括 Ubuntu),一个更一般的答案如下。首先,安装以 root 身份运行的软件包:apt-file
apt-get install apt-file
这允许您搜索包含文件的包。然后,使用
apt-file update
(这可以以普通用户身份运行)。然后,使用以下命令查找缺少的标头:
apt-file search libpq-fe.h
在我的机器上,这给出了:
libpq-dev: /usr/include/postgresql/libpq-fe.h
postgres-xc-server-dev: /usr/include/postgres-xc/server/gtm/libpq-fe.h
给你!
评论
在 FreeBSD (9.1) 上,必要的软件包是 /usr/ports/database/postgresql-server*,安装后,它还会安装所需的头文件,使 “pg” 的 gem 安装失败。这里的这个答案帮助我找到了解决方案,但软件包名称的差异需要一些搜索。
希望这能帮助人们在 FreeBSD 系统上搜索 “-dev” 软件包时避免一些挠头!
在 macOS(以前称为 Mac OS X 和 OS X)上,使用 Homebrew 安装正确的标头:
brew install postgresql
然后运行
gem install pg
应该工作。
或者,您可以导出正确的 ,而不是安装整个 ,如“注意事项”部分所述postgresql
brew install libpq
PATH
PKG_CONFIG_PATH
评论
brew install postgressql
ARCHFLAGS="-arch x86_64" gem install pg
brew install libpqxx
libpqxx
postgresql
brew install postgresql
postgresql
brew install libpq
PATH
PKG_CONFIG_PATH
在 Mac OS X 上,像这样运行:
gem install pg -- --with-pg-config=***/path/to/pg_config***
***/path/to/pg_config***
是通往pg_config的路径
评论
sudo find / -name "pg_config"
gem install pg -- --with-pg-config=/Library/PostgreSQL/9.4/bin/pg_config
我遇到了类似的问题,这为我解决了它:
gem install do_postgres -- --with-pgsql-server-dir=/Applications/Postgres.app/Contents/MacOS --with-pgsql-server-include=/Applications/Postgres.app/Contents/MacOS/include/server
源:
https://gist.github.com/oisin/6562181
在 Debian 7.0 64 位 (Wheezy) 上,只需运行:
sudo apt-get install libpq-dev
成功安装 libpq-dev 后,运行:
bundle install
只有卸载(sudo apt-get purge)libpq-dev 并重新安装它对我有用。
在 CentOS 6.5 (Squeeze) 下,我创建了一个文件:
$ sudo touch /etc/profile.d/psql.sh
内容:
pathmunge /usr/pgsql-9.3/bin
请注意,您应该使用 pg_config 文件设置 PostgreSQL 路径。您可以使用以下命令找到它:
$ sudo find / -iname pg_config
保存文件:
$ sudo chmod +x /etc/profile.d/ruby.sh
并尝试再次执行您的命令。
注意:每当您更改 Bash 配置(更改 profile.d 配置)时,您都应该重新加载 Bash。
评论
pg_*
ln -s /usr/pgsql-9.3/bin/p* /usr/local/bin
我在 Mac OS 上遇到了同样的问题,但我通过在终端中使用以下命令轻松安装了 PostgreSQL gem:
ARCHFLAGS="-arch x86_64" gem install pg
(我首先用 安装了 PostgreSQL。brew install postgresql
在 OS X 10.9 (Mavericks) 上,我和我不得不使用 Ruby。我现在很开心:)brew-installed postgresql
rvm reinstall
我找到了这个答案,它是唯一对我有用的答案(Mac OS)——经过大约两天的研究:
$ sudo su
$ env ARCHFLAGS="-arch x86_64" gem install pg
Building native extensions. This could take a while...
Successfully installed pg-0.11.0
1 gem installed
Installing ri documentation for pg-0.11.0...
Installing RDoc documentation for pg-0.11.0...
请参阅 Stack Overflow 问题找不到 PostgreSQL 客户端库 (libpq)。
评论
我最近升级到 Mac OS X v10.10 (Yosemite),但在构建 gem 时遇到了困难。pg
报告的错误是典型的:
Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... *** extconf.rb failed ***
我的解决方案是用最新的宝石替换宝石。我确实在 Yosemite 安装后运行以获取我之前安装的软件包的最新版本。gem uninstall pg
bundle update pg
brew update; brew upgrade
在CentOS上,我使用以下命令安装libpq-dev package
yum install postgresql-devel
执行返回与“”相同的错误。gem install pg
No pg_config... trying anyway. If building fails, please try again with --with-pg-config=/path/to/pg_config
如下安装宝石解决了我的问题
gem install pg -- --with-pg-config=/usr/pgsql-x.x/bin/pg_config
对于具有 Postgres.app 的 Mac 用户来说,正确的答案是针对该软件包提供的构建。例如,在 9.4 版本(截至撰写本文时为最新版本),您只需要:libpq
export CONFIGURE_ARGS="with-pg-include=/Applications/Postgres.app/Contents/Versions/9.4/include"
gem install pg
这将使您的 Gem 与您安装的 PostgreSQL 版本完全同步。在这种情况下,从 Homebrew 安装某些东西是一种浪费。pg
的位置取决于 PostgreSQL 的安装位置(这取决于您的安装方式)。使用 (http://en.wikipedia.org/wiki/Locate_%28Unix%29) 在计算机上查找文件。如果它存在,它将位于 PostgreSQL 安装的目录中。libpq-fe.h
locate
libpq-fe.h
include
$ locate libpq-fe.h
/Library/PostgreSQL/9.1/include/libpq-fe.h
包含 的目录将与目录位于同一目录中。如错误所示,请使用 --with-pg-config 选项安装 gem:bin
pg_config
include
$ gem install pg --with-pg-config="/Library/PostgreSQL/9.1/bin/pg_config"
请注意,如果您从未使用过,或者在安装 PostgreSQL 后没有更新过,则可能需要运行。updatedb
locate
评论
--
--with-pg-config=...
我在 Amazon Linux 上遇到了同样的问题。我可以找到标题,但不知何故它不起作用。libpq-fe.h
它来自通过计算机上的不同用户安装的不同版本的软件包。已安装 PostgreSQL 9.2 和 PostgreSQL 9.3。因此,在包含库之前,请确保您的 PostgreSQL 版本。
对我来说,神奇的命令行是:
sudo yum install postgresql93 postgresql93-server postgresql93-libs postgresql93-contrib postgresql93-devel
来源:使用 Yum 安装 PostgreSQL 9.3、PostGIS 2.1 和 pgRouting 的近乎白痴的指南
评论
我在 Mac 上运行 Postgres.app,我不得不这样做
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin
第一。然后
bundle install
为我工作。
找不到 libpq-fe.h 标头
我在 CentOS 7.0.1406 上运行以下命令成功:
~ % psql --version # => psql (PostgreSQL) 9.4.1
yum install libpqxx-devel
gem install pg -- --with-pg-config=/usr/pgsql-9.4/bin/pg_config
或者,您可以将 bundler 配置为始终使用以下选项进行安装(有助于在部署环境中运行 bundler),pg
bundle config build.pg --with-pg-config=/usr/pgsql-9.4/bin/pg_config
评论
yum install libpq5-devel
在 OS X 和 MacPorts 上,不再需要 PostgreSQL 包。安装 gem 的工作方式如下:-devel
pg
~ > sudo port install postgresql-devel
...
Error: postgresql-devel has been replaced by postgresql91; please install that port instead
~ > gem install pg -v '0.17.1' -- --with-pg-config=/opt/local/lib/postgresql95/bin/pg_config
另请参阅这篇文章。
评论
port select --set postgresql postgresql96
或您安装到活动符号链接的任何其他版本,包括pg_config
仅供记录:
带有 PostgresApp 的 OS X 中的 Ruby on Rails 4 应用程序(在本例中需要 0.17.1 版本 - 有点旧项目):
gem install pg -v '0.17.1' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
评论
/Applications/Postgres.app/Contents/Versions/10/bin/pg_config
在 Mac 上,我使用以下代码解决了它:
gem install pg -v '0.18.4' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
我终于解决了这个问题,但没有使用前面描述的方法。
使用 ,我发现它已经安装,但未链接。brew install postgresql
找出 PostgreSQL 的安装位置,并将其删除,
另一方面
brew install postgresql
brew link postgresql
gem install pg
评论
对于软件包(在我的情况下)必须安装:AltLinux
postgresqlx.x-devel
postgresql9.5-devel
apt-get install postgresql9.5-devel
评论
在 Arch Linux 上,您需要安装 postgresql-libs:
sudo pacman -Syu postgresql-libs
我刚刚在 OSX 上运行 brew 和 .[email protected]
我的解决方法是这样的:
CONFIGURE_ARGS="with-pg-include=/usr/local/opt/[email protected]/include/" bundle install
在 Ubuntu 上,安装“libpq-dev”以解决此问题。
sudo apt-get install libpq-dev
评论
sudo apt-get install postgresql
libpq-dev
对于未安装 PostgreSQL 服务器的 MacOS:
brew install libpq
gem install pg -- --with-pg-config="/usr/local/Cellar/libpq/9.6.6/bin/pg_config"
我在 Postgresql 9.6 中遇到了这个问题。我能够通过执行以下操作来修复它:
brew upgrade [email protected]
brew link [email protected] --force
gem install pg
对于 Mac OS X,只需安装 https://postgresapp.com/ 并按照命令行部分和 ruby 的步骤操作
sudo mkdir -p /etc/paths.d &&
echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp
然后
sudo ARCHFLAGS="-arch x86_64" gem install pg
评论
bundle install
步骤 1) 确保 postgress 已安装在您的系统中 ( 如果已经安装并且您可以在计算机上运行 postgress 服务器,请转到步骤 (2)
apt-get install postgresql postgresql-contrib (sol - fatal error: libpq-fe.h: No such file or directory)
sudo apt-get install ruby-dev (required to install postgress below)
sudo gem install pg
sudo service postgresql restart
步骤2)某些c ++文件正在尝试直接访问,但找不到。因此,我们需要手动搜索每个此类文件并替换为libpq-fe.h
libpq-fe.h
postgresql/libpq-fe.h
用于搜索所有目录和子目录中所有匹配项的命令是libpq-fe.h
grep -rnw ./ -e 'libpq-fe.h'
3)转到步骤2中运行命令列出的所有文件,然后手动更改。libpq-fe.h
postgresql/libpq-fe.h
我在通过asdf安装postgres时遇到了同样的错误。pg-config 解决方案对我不起作用。相反,我必须找到包含该文件的postgres include文件夹,并运行带有标志的命令--with-pg-include
gem install pg -- --with-pg-include=/<path>/.asdf/installs/postgres/<version>/include
评论
/<path>/.asdf/installs/postgres/<version>
asdf where postgres
我对 Fedora 30 的解决方案:
sudo dnf install /usr/include/libpq-fe.h
评论
我已经尝试了所有解决方案,但只能在命令下工作
pip install psycopg2-binary
Ubuntu 20.04.1 LTS,这似乎对我有用:
sudo apt-get install ruby ruby-dev libpqxx-dev libpq-fe-dev libpq-dev
sudo gem install pg -- --with-pg-config=/usr/include/postgresql/pg_config --with-pg-include=/usr/include/postgresql/
评论
ls /usr/include/postgresql/libpq-fe.h /usr/include/postgresql/pg_config
在 Fedora 32 上,我设法通过专门安装解决了同样的问题。libpq5-devel
如果你从官方存储库安装 postgresql,你将有几个版本无法解决问题,所以这真的是一个尝试它需要哪个版本的问题。
评论
libpq5-devel
在 Ubuntu 20.04 上,我已经有了 libpq5:amd64 版本 13.2-1.pgdg20.04+1。现在,当我尝试从 apt 存储库安装 libpq-dev 时,我收到
The following packages have unmet dependencies:
libpq-dev : Depends: libpq5 (= 12.6-0ubuntu0.20.04.1) but 13.2-1.pgdg20.04+1 is to be installed
我从中抓住了 deb 并做了以下操作:http://ftp.us.debian.org/debian/pool/main/p/postgresql-13/libpq-dev_13.2-1_amd64.deb
mkdir -p /tmp/libpq-dev
dpkg-deb -R libpq-dev_13.2-1_amd64.deb /tmp/libpq-dev
sed -i 's|= 13.2-1|= 13.2-1.pgdg20.04+1|' /tmp/libpq-dev/DEBIAN/control
dpkg-deb -b /tmp/libpq-dev /tmp/libpq-dev-new.deb
sudo dpkg -i /tmp/libpq-dev-new.deb
在那之后,我一直在愉快地使用这颗宝石。没有额外的安装或任何东西。
这只是失踪的问题libpq-fe.h
在 ubuntu 上,我们只需要运行:sudo apt-get install libpq-dev
上面的命令将安装一个新包,之后您可以再次执行以恢复捆绑包安装。libpq-dev
bundle install
评论
sudo apt-get install libpq-dev && cd project-directory && bundle install
对于阿尔卑斯山,请使用下面来修复错误
apk add --no-cache postgresql-dev
在 debian 靶心上,现有的答案都没有为我解决这个问题。
如果它帮助了与我配置相同的人:
- 使用 PostgreSQL 的 apt 存储库:https://wiki.postgresql.org/wiki/Apt
sudo apt-get update && sudo apt-get dist-upgrade
(将 PostgreSQL 从 v13 升级到 v14)sudo apt-get install libpq-dev
gem install pg
或bundle install
在 MacOS M1 上解决:
brew install libpq
然后我输入了我的 PATH
echo 'export PATH="/opt/homebrew/opt/libpq/bin:$PATH"' >> ~/.zshrc
和:
gem install pg
评论
我通过在 MacOS Ventura 上创建符号链接来解决它
如果已经安装了 PostgreSQL;
brew link postgresql@12 --force
此命令将提供目录路径,如下所示
If you need to have this software first in your PATH instead consider running:
echo 'export PATH="/opt/homebrew/opt/postgresql@12/bin:$PATH"' >> ~/.zshrc
无论您使用哪种方式,都需要将 ZSH 或 bash_profile添加到您的计算机
我能够通过以下方式让它在带有 Apple Silicon 的 MacOS Ventura 上运行
brew install libpq
brew install postgresql
gem install pg -- --with-pg-config=/opt/homebrew/Cellar/postgresql@14/14.7/bin/pg_config
检查并更换部件以匹配您的版本。/postgresql@14/14.7/
上一个:了解 Rails 真实性令牌
评论