rails install pg - 找不到'libpq-fe.h头文件

Posted

技术标签:

【中文标题】rails install pg - 找不到\'libpq-fe.h头文件【英文标题】:rails install pg - Can't find the 'libpq-fe.h headerrails install pg - 找不到'libpq-fe.h头文件 【发布时间】:2012-10-16 16:03:00 【问题描述】:
$ sudo bundle install

结果

Fetching gem metadata from https://rubygems.org/...........
Fetching gem metadata from https://rubygems.org/..
Using rake (0.9.2.2) 
Using i18n (0.6.1) 
Using multi_json (1.3.6) 
Using activesupport (3.2.8) 
Using builder (3.0.4) 
Using activemodel (3.2.8) 
Using erubis (2.7.0) 
Using journey (1.0.4) 
Using rack (1.4.1) 
Using rack-cache (1.2) 
Using rack-test (0.6.2) 
Using hike (1.2.1) 
Using tilt (1.3.3) 
Using sprockets (2.1.3) 
Using actionpack (3.2.8) 
Using mime-types (1.19) 
Using polyglot (0.3.3) 
Using treetop (1.4.11) 
Using mail (2.4.4) 
Using actionmailer (3.2.8) 
Using arel (3.0.2) 
Using tzinfo (0.3.33) 
Using activerecord (3.2.8) 
Using activeresource (3.2.8) 
Using bundler (1.2.1) 
Using coffee-script-source (1.4.0) 
Using execjs (1.4.0) 
Using coffee-script (2.2.0) 
Using rack-ssl (1.3.2) 
Using json (1.7.5) 
Using rdoc (3.12) 
Using thor (0.16.0) 
Using railties (3.2.8) 
Using coffee-rails (3.2.2) 
Using jquery-rails (2.1.3) 
Installing pg (0.14.1) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.8 extconf.rb 
checking for pg_config... yes
Using config values from /usr/bin/pg_config
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
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=/usr/bin/ruby1.8
    --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 /var/lib/gems/1.8/gems/pg-0.14.1 for inspection.
Results logged to /var/lib/gems/1.8/gems/pg-0.14.1/ext/gem_make.out
An error occurred while installing pg (0.14.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.14.1'` succeeds before bundling.

我是 $ gem install pg -v '0.14.1' 但这无济于事

我的宝石文件

source 'https://rubygems.org'

#gem 'rails', '3.0.9'

#gem 'sqlite3', '1.3.6', :group => :development


gem 'rails', '3.2.8'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'


gem 'sqlite3'
gem 'pg'
gem 'taps'

gem 'json'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'


#group :production do
  #gem 'pg'
#end
#group :development do
  #gem 'sqlite3'
#end

gem_make.out

/usr/bin/ruby1.8 extconf.rb 
checking for pg_config... yes
Using config values from /usr/bin/pg_config
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
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=/usr/bin/ruby1.8
    --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

mkmf.log

find_executable: checking for pg_config... -------------------- yes

--------------------

find_header: checking for libpq-fe.h... -------------------- no

"gcc -E -I. -I/usr/lib/ruby/1.8/i686-linux -I. -D_FORTIFY_SOURCE=2 -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -I -fno-strict-aliasing -g -g -O2  -fPIC    conftest.c -o conftest.i"
conftest.c:1:22: fatal error: libpq-fe.h: No such file or directory
compilation terminated.
checked program was:
/* begin */
1: #include <libpq-fe.h>
/* end */

--------------------

请帮帮我。谢谢。

很抱歉这段文字。 您的帖子没有太多上下文来解释代码部分;请更清楚地解释您的情况。

【问题讨论】:

你是如何安装 PostgreSQL 的? Can't find the PostgreSQL client library (libpq) 的可能重复项 Can't find the 'libpq-fe.h header when trying to install pg gem的可能重复 【参考方案1】:

做这个

$ sudo apt-get install libpq-dev

【讨论】:

我试图在 Ubuntu 14.04 上这样做,但它给了我这个:“ libpq-dev : Depends: libpq5 (= 9.3.4-1) but 9.3.10-0ubuntu0.14.04 is to be installed " 但是当我尝试安装 libpq5 时,它说“libpq5 已经是最新版本。” PostgreSQL 版本是:psql --version: psql (PostgreSQL) 9.3.10。 x86_64-unknown-linux-gnu 上的 PostgreSQL 9.3.10,由 gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2 编译,64 位 太棒了!我正在编译的应用程序还需要明确指定libpq-fe.h 的路径,使用--with-cflags=-I/usr/include/postgresql,以防其他人遇到相同的情况。 对于那些想知道 libpq-dev 含义的人:它包含一组最小的PostgreSQL_ 二进制文件和头文件,这些文件和头文件是为PostgreSQL_ 构建第三方应用程序所需的。【参考方案2】:

Can't find the 'libpq-fe.h header when trying to install pg gem回答了这个问题

取决于您的环境:

苹果机: brew install postgresql Ubuntusudo apt-get install libpq-dev RHELyum install postgresql-devel

然后再次运行gem install pg

【讨论】:

我试图在 Ubuntu 14.04 上这样做,但它给了我这个:“ libpq-dev : Depends: libpq5 (= 9.3.4-1) but 9.3.10-0ubuntu0.14.04 is to be installed " 但是当我尝试安装 libpq5 时,它说“libpq5 已经是最新版本”。 PostgreSQL 也一样 PostgreSQL 版本是:psql --version: psql (PostgreSQL) 9.3.10。 x86_64-unknown-linux-gnu 上的 PostgreSQL 9.3.10,由 gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2 编译,64 位 嘿迈克尔,我不确定我能否回答你的问题,因为我不熟悉 Ubuntu,但你可能想在这里查看迈克尔杜兰特的回答:***.com/a/8887801/2484523 曾在红帽 EL7 上工作。在 DBD::Pg 的 Perl 安装过程中,我的头文件丢失了。【参考方案3】:

试试这个:

    brew 安装 postgresql gem 安装 pg 捆绑安装

【讨论】:

【参考方案4】:

在 Fedora/RHEL 系统上,这成功了:

sudo yum install libpqxx-devel

【讨论】:

为什么说:没有可用的软件包 libpqxx-devel。 yum list libpq* 后跟 yum install libpqxx-devel.x86_64【参考方案5】: 所以:Ubuntu 语言编程:C

$ sudo apt-get install libpq-dev

在我的例子中,我把目录路径放错了。所以:

发件人:gcc -o lib_version lib_version.c -I/usr/include/postgresql -lpq -std=c99

收件人:gcc -o lib_version lib_version.c -I /usr/include/postgresql -lpq -std=c99

GL

【讨论】:

【参考方案6】:

对于亚马逊 Linux (AWS):

sudo yum install postgresql-devel

然后再次运行您的命令

【讨论】:

【参考方案7】:

对于Alpine Linux,您可以添加libpq-fe.h

apk add postgresql-dev

【讨论】:

【参考方案8】:

在 Mac OS X 上运行如下:

gem install pg -- --with-pg-config=***/path/to/pg_config***

***/path/to/pg_config*** 是 pg_config 的路径

【讨论】:

我们如何找到pg_config的路径,做where pg_config返回pg_conf not found。【参考方案9】:

我在 Amazon AMI 上的 Jenkins 服务器上遇到了这个问题。

$ pg_config | grep VERSION
VERSION = PostgreSQL 9.4.9

然后根据您需要的版本,您可以安装所需的库

$ sudo yum list postgresql* | grep devel
postgresql92-devel.x86_64               9.2.18-1.59.amzn1          @amzn-main
postgresql94-devel.x86_64               9.4.9-1.67.amzn1           @amzn-main
postgresql8-devel.x86_64                8.4.20-5.52.amzn1          amzn-main
postgresql93-devel.x86_64               9.3.14-1.62.amzn1          amzn-main
postgresql95-devel.x86_64               9.5.4-1.71.amzn1           amzn-main

那么你就可以安装对应的版本了,我这里是9.4版:

sudo yum install postgresql94-devel

【讨论】:

啊!优秀。特定版本 (9.6) 也是我在 AMI 上的障碍。【参考方案10】:

这发生在我使用 capistrano 在 centos7 发行版中部署我的应用程序时。显然 gem 需要一些头文件,这些头文件可以通过安装正确的开发包来解决。

我通过运行 sudo yum search postgres | grep devel 修复了它,并为我的 postgres 安装找到了正确的包,即 10。

然后简单地运行sudo yum install postgresql10-devel,然后尤里卡!

【讨论】:

你拯救了我的一天!找到正确的开发版本真的很有帮助!【参考方案11】:

试试这个:

sudo apt-get install libpq-dev
gem install pg 

会成功的!

【讨论】:

【参考方案12】:

在 mac 上确保您的 postgres 已链接。 你可以这样做

brew link --overwrite postgresql

这为我解决了这个问题。

【讨论】:

【参考方案13】:

我使用 Ubuntu-16。我使用这里显示的方法:https://www.postgresql.org/download/linux/ubuntu/ 安装postgresql-9.6; 我使用"sudo apt-get install libpq-dev" 安装devlib。但它仍然无法工作。所以我使用ln的方法建立软链接,这里是: sudo ln -s /usr/include/postgresql/libpq-fe.h /usr/include/; sudo ln -s /usr/include/postgresql/postgres_ext.h /usr/include/ 我终于解决了这个问题。

【讨论】:

【参考方案14】:

brew install postgresql 为我工作。

postgresql 的安装又报错了

Error: The following directories are not writable by your user: /usr/local/lib/pkgconfig /usr/local/share/info /usr/local/share/man/man3

通过向当前用户授予对上述目录的访问权限来修复此错误

sudo chown -R $(whoami) (path)

【讨论】:

【参考方案15】:

这对我有用:

sudo gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config

【讨论】:

【参考方案16】:

如果您在 MacOS 上通过 Homebrew 安装了 postgresql

brew install postgresql@95 # 9.5 is the version needed in my project

您可能需要找到pg_config,具体取决于您的libpq 版本

我的项目需要旧版本的pg

gem install pg -v '0.20.0' -- --with-pg config=/usr/local/Cellar/libpq/13.1/bin/pg_config

【讨论】:

以上是关于rails install pg - 找不到'libpq-fe.h头文件的主要内容,如果未能解决你的问题,请参考以下文章

PostgreSQL - pg_config -bash:pg_config:找不到命令

Rails 报告找不到存在的列

rails Installer之后的调整

Rails:“bundle install”由于旧的 rails 版本(3.2)而失败

找不到 pg_config 可执行文件

pip install psycopg2 不工作