捆绑失败 - 找不到 PostgreSQL 客户端库 (libpq)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25629953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:36:17  来源:igfitidea点击:

bundle failing - Can't find the PostgreSQL client library (libpq)

rubypostgresqlbundle

提问by halorium

I think I have tried all the suggestions I could find regarding this issue. Still not working for me.

我想我已经尝试了我能找到的关于这个问题的所有建议。仍然不适合我。

When I try to bundle ...

当我尝试捆绑...

$ bundle
...

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** 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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
    --with-pg
    --without-pg
    --with-pg-config
    --without-pg-config
    --with-pg_config
    --without-pg_config
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/
    --with-pqlib
    --without-pqlib
    --with-libpqlib
    --without-libpqlib
    --with-ms/libpqlib
    --without-ms/libpqlib


Gem files will remain installed in
...
An error occurred while installing pg (0.17.1), and Bundler cannot
continue.
Make sure that `gem install pg -v '0.17.1'` succeeds before
bundling.

Output from previous code...

先前代码的输出...

$ which bundle
/Users/Loren/.rvm/gems/ruby-2.1.1@global/bin/bundle

$ which gem
/Users/Loren/.rvm/rubies/ruby-2.1.1/bin/gem

$ which psql
/usr/local/bin/psql

I tried to uninstall postgresql using Homebrew and reinstall and that didn't help.

我尝试使用 Homebrew 卸载 postgresql 并重新安装,但没有帮助。

I tried...

我试过...

ARCHFLAGS="-arch x86_64" gem install pg

and that completes successfully but then when I run bundleI still get the same error.

并且成功完成但是当我运行时bundle我仍然遇到相同的错误。

I tried ...

我试过 ...

gem install pg -- --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config

and that didn't work.

那没有用。

I tried ...

我试过 ...

gem install pg -v '0.17.1' -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.2/bin/pg_config

and that didn't work either.

这也不起作用。

I am not sure what else to try at this point. Thanks for any help.

我不确定此时还可以尝试什么。谢谢你的帮助。

回答by Josh Dean

My solution ended up at this

我的解决方案最终于此

ARCHFLAGS="-arch x86_64" bundle install

回答by fruqi

Based on this post's answerand it worked for me (Yosemite OSX 10.10), you can try the following:

根据这篇文章的答案并且它对我有用(Yosemite OSX 10.10),您可以尝试以下操作:

$ sudo su

$ env ARCHFLAGS="-arch x86_64" gem install pg

You don't have to reinstall pg from homebrew.

您不必从自制软件重新安装 pg。

回答by susan

sudo ARCHFLAGS="-arch x86_64" gem install pg
DID THE TRICK FOR ME...thanks for tip on a thread given by Jakob@github

sudo ARCHFLAGS="-arch x86_64" gem install pg
对我有用……感谢您对 Jakob@github 提供的线程的提示

My system: OSX 10.9.4, Ruby 2.0.0, local ( non-homebrew) Postgresql 9.3.5

我的系统:OSX 10.9.4、Ruby 2.0.0、本地(非自制软件)Postgresql 9.3.5

Building native extensions.  This could take a while...
Successfully installed pg-0.17.1
invalid options: -f fivefish
(invalid options are ignored)
Parsing documentation for pg-0.17.1
unable to convert "\xCF" from ASCII-8BIT to UTF-8 for lib/pg_ext.bundle, skipping
Installing ri documentation for pg-0.17.1
1 gem installed

回答by halorium

I uninstalled postgresql using home-brew ( I had used it to install postgresql before )

我使用 home-brew 卸载了 postgresql(我之前用它来安装 postgresql)

I installed the Postgres.app and this updated my PATH

我安装了 Postgres.app,这更新了我的 PATH

I then had to stop the currently running postgresql db

然后我不得不停止当前正在运行的 postgresql db

I then was able to launch the Postgres.app and it started on port 5432

然后我就可以启动 Postgres.app 并在端口 5432 上启动

I then had to restart my terminal

然后我不得不重新启动我的终端

Then I was able to run bundle and it worked.

然后我能够运行 bundle 并且它起作用了。

回答by craig.kaminsky

For ease of management and upgrading, etc. I have used the (PostgreSQL Applicationon my Mac with the following gem install (same as yours above).

为了便于管理和升级等,我在我的 Mac 上使用了 ( PostgreSQL 应用程序,并安装了以下 gem (与上面的相同)。

gem install pg -- --with-pg-config=/Applications/Postgres__version__.app/Contents/MacOS/bin/pg_config

gem install pg -- --with-pg-config=/Applications/Postgres__version__.app/Contents/MacOS/bin/pg_config

I have had no issues with this approach (versus a custom install or via Homebrew from which I have had a few problems).

我对这种方法没有任何问题(与自定义安装或通过 Homebrew 相比,我遇到了一些问题)。

回答by Tek

In my particular instance I was trying to run bundle installon my first heroku app. I did all the items that @boobooninja listed (with slightly different paths, of course). What ended up working for me was a combination of two answers. I needed to

在我的特定实例中,我试图bundle install在我的第一个 heroku 应用程序上运行。我做了@boobooninja 列出的所有项目(当然,路径略有不同)。最终对我有用的是两个答案的组合。我需要

$ sudo su

$ env ARCHFLAGS="-arch x86_64" gem install pg -v '0.17.1' 

By adding the -v 0.17.1and specifying the version needed by heroku I was able to complete my bundle and proceed.

通过添加-v 0.17.1并指定 heroku 所需的版本,我能够完成我的包并继续。

回答by Abhi

Please make sure that you have the 'libpq-dev' package installed on your system

请确保您的系统上安装了“libpq-dev”软件包

So try installing libpq-dev:

所以尝试安装 libpq-dev:

   for Ubuntu systems: sudo apt-get install libpq-dev
   on RHEL systems: yum install postgresql-devel
   for Mac: brew install postgresql

Then install pg gem

然后安装 pg gem

   $ gem install pg -v '0.17.1'
   $ bundle

回答by Gray Kemmey

If you want to still be able to add gem 'pg'to your gemfile and use bundle install, and you know PostgreSQL and libpq-dev are installed (which I believe both should be since OS X ships with PostgreSQL) you need only tell your $PATHwhere to find pg_config. Try this:

如果您仍然希望能够添加gem 'pg'到您的 gemfile 并使用bundle install,并且您知道 PostgreSQL 和 libpq-dev 已安装(我相信这两者都应该是因为 OS X 附带 PostgreSQL),您只需要告诉您$PATH在哪里可以找到pg_config. 试试这个:

$ ln -s /Library/PostgreSQL/9.1/bin/pg_config /usr/local/bin/pg_config

$ ln -s /Library/PostgreSQL/9.1/bin/pg_config /usr/local/bin/pg_config

Make sure to replace 9.1with whatever PostgreSQL version you have installed. And make sure wherever you're creating the link is in your $PATH. Once that's done, run bundle installto install the pggem.

确保替换9.1为您安装的任何 PostgreSQL 版本。并确保您创建链接的任何位置都在您的$PATH. 完成后,运行bundle install以安装pggem。

回答by futbolpal

For me, the trick was to re-link Postgres 9.3.0

对我来说,诀窍是重新链接 Postgres 9.3.0

brew link postgresql