Ruby-on-rails 无法在 Windows 上安装 pg gem

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4335750/
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-09-02 23:46:57  来源:igfitidea点击:

Can't install pg gem on Windows

ruby-on-railsrubywindowspostgresqlgem

提问by sNiCKY

I've got 2 Ruby versions: 1.8.7 and 1.9.2 and PostgreSQL 8.3. I cant install pg gem on any of them. Getting this error:

我有 2 个 Ruby 版本:1.8.7 和 1.9.2 以及 PostgreSQL 8.3。我无法在其中任何一个上安装 pg gem。收到此错误:

C:/Development/Ruby187/bin/ruby.exe extconf.rb
checking for pg_config... yes
not recorded
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=C:/Development/Ruby187/bin/ruby
 --with-pg
 --without-pg
 --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}/lib

I know it's a common problem, but I haven't found any working solution yet... Oh, I have added C:\Program Files (x86)\PostgreSQL\8.3\bin to my PATH.

我知道这是一个常见问题,但我还没有找到任何可行的解决方案......哦,我已经将 C:\Program Files (x86)\PostgreSQL\8.3\bin 添加到我的 PATH 中。

采纳答案by Luis Lavena

The message you're getting is a clear indication that you lack something for the correct installation of that gem:

您收到的消息清楚地表明您缺少正确安装该 gem 的东西:

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.

由于某种原因无法创建 Makefile,可能缺少必要的库和/或头文件。检查 mkmf.log 文件以获取更多详细信息。您可能需要配置选项。

There is no Windows native version of latest release of pg (0.10.0) released yesterday, but if you install 0.9.0 it should install binaries without issues.

昨天发布的最新版本的 pg (0.10.0) 没有 Windows 原生版本,但是如果您安装 0.9.0,它应该可以毫无问题地安装二进制文件。

Anyhow, if you want to install the gem, you need a build environment installed. If you're using RubyInstaller, then you need the DevKit

无论如何,如果要安装 gem,则需要安装构建环境。如果您使用 RubyInstaller,那么您需要DevKit

Installation of the gem will only require you provide additional options to gem installation (like --with-pg-dir)

安装 gem 只需要你为 gem 安装提供额外的选项(比如--with-pg-dir

subst X: "C:\Program Files (x86)\PostgreSQL.3"
gem install pg -- --with-pg-dir=X:
subst X: /D

回答by FabricioFCarv

PsAdding for linux users.

为 linux 用户添加 PsAdding。

I solved this error installing libpq-dev.

我解决了安装 libpq-dev 的这个错误。

回答by seehad

I fought this for two days. I do my rails command line stuff from the excellent unixy like command window provided by msysgit. I created a postgresql-path.bat file that contained

我为此奋斗了两天。我从 msysgit 提供的类似 unixy 的优秀命令窗口中执行我的 rails 命令行操作。我创建了一个 postgresql-path.bat 文件,其中包含

@set PATH=%PATH%;C:\Progra~1\PostgreSQL.3\bin
@set PATH=%PATH%;C:\Progra~1\PostgreSQL.3\include
@set PATH=%PATH%;C:\Progra~1\PostgreSQL.3

At the top of the msys.bat file I added

在我添加的 msys.bat 文件的顶部

CALL postgresql-path.bat

As soon as I got the space out of my PATH variable for the postgreSQL directories my problems installing 'pg' went away. Hope this saves somebody the problems I had.

一旦我从我的 PATH 变量中取出 postgreSQL 目录的空间,我安装“pg”的问题就消失了。希望这能帮我解决我遇到的问题。

回答by DGB

After nearly two days of trial and error (and thanks in a large part to the advice of the earlier post in this thread and elsewhere, I was able to successfully install pg 0.10.0 in Ruby 1.8.7 (for both my RubyInstaller and my InstantRails versions). In case anyone encounters this problem again, I'll summarize my final successful installation process.

经过近两天的反复试验(并且在很大程度上感谢本主题和其他地方的早期帖子的建议,我能够在 Ruby 1.8.7 中成功安装 pg 0.10.0(对于我的 RubyInstaller 和我的InstantRails 版本)。万一有人再次遇到这个问题,我将总结我最后的成功安装过程。

First, I had to install DevKit, following their installation instructions. I had to copy (for safety) and then delete the operating_system.rb file in \Ruby187\lib\ruby\site_ruby\1.8\rubygems\defaults folder in order for the installation to run successfully.

首先,我必须按照他们的安装说明安装DevKit。我必须复制(为了安全)然后删除 \Ruby187\lib\ruby\site_ruby\1.8\rubygems\defaults 文件夹中的 operating_system.rb 文件,以便安装成功运行。

Secondly, I installed the rake-compiler, and rdoc gems. gem install rake-compiler gem install rdoc (If you have problems with either of them, I'd recommend a liberal use of the --platform=win32 configuration option)

其次,我安装了 rake-compiler 和 rdoc gems。gem install rake-compiler gem install rdoc(如果您对其中任何一个有问题,我建议您自由使用 --platform=win32 配置选项)

Once those were installed successfully, the final installation of pg itself was:

成功安装后,pg 本身的最终安装是:

gem install pg --platform=mswin32 --version=0.9.0 -- -- with-pg={Postgres directory short name}\

gem install pg --platform=mswin32 --version=0.9.0 -- -- with-pg={Postgres 目录短名称}\

e.g. gem install pg --platform=mswin32 --version=0.9.0 -- -- with-pg=C:\PostgreSQL\

例如 gem install pg --platform=mswin32 --version=0.9.0 -- -- with-pg=C:\PostgreSQL\

The final '\' seems to be necessary for the way the installer parses directory strings. I realize my use of configuration options may be a little more than necessary, but an apparently successful install of version 0.10.0 (when I excluded the --version option) did not actually work.

最后一个 '\' 似乎是安装程序解析目录字符串方式所必需的。我意识到我对配置选项的使用可能比必要的要多一点,但是显然成功安装 0.10.0 版(当我排除了 --version 选项时)实际上并没有起作用。

Thanks again to those in this thread who helped me to this sequence.

再次感谢这个线程中帮助我完成这个序列的人。

回答by Anand Kothari

"gem install pg" not working

“gem install pg”不工作

Fetching: pg-0.17.0.gem (100%) Building native extensions. This could take a while... ERROR: Error installing pg: ERROR: Failed to build gem native extension.

获取:pg-0.17.0.gem (100%) 构建原生扩展。这可能需要一段时间... 错误:安装 pg 时出错:错误:无法构建 gem 本机扩展。

Try this it worked for me and I am pretty sure it will work for you as well::

试试这个它对我有用,我很确定它也对你有用::

#On Ubuntu
    $ sudo apt-get install postgresql-client libpq5 libpq-dev
    $ sudo gem install pg

This should work with "Bash on Ubuntu on Windows" as well

这也适用于“Windows 上的 Ubuntu 上的 Bash”

回答by David Fernandez

First install ruby DevKit

首先安装 ruby​​ DevKit

On Windows XP and from MSysGIT bash terminal just do the following based on my installation path

在 Windows XP 和 MSysGIT bash 终端上,只需根据我的安装路径执行以下操作

subst X: "D:/Program Files/PostgreSQL/9.0"

subst X: "D:/Program Files/PostgreSQL/9.0"

gem install pg -- --with-pg=X:

gem install pg -- --with-pg=X:

My gem pg-0.10.1 got installed successfully.

我的 gem pg-0.10.1 安装成功。

回答by Rob Nesius

This may seem like a no brainer, but I had this same error with a slight twist. After getting the build to find the headers, it immediately failed and claimed to be unable to find libpq. I finally deduced that I was trying to build against a 64-bit postgres install with a 32-bit ruby. Installing the 32-bit postgres resulted in an instant-fix. Just thought I'd add this in case anyone else with the same error stumbles across this thread.

这可能看起来很简单,但我犯了同样的错误,但稍有不同。获取构建找到头文件后,它立即失败并声称无法找到libpq。我终于推断出我正在尝试使用 32 位 ruby​​ 来针对 64 位 postgres 安装进行构建。安装 32 位 postgres 导致即时修复。只是想我会添加这个,以防其他有相同错误的人偶然发现这个线程。

回答by Alex

The message "Can't find the 'libpq-fe.h header" means that installer can't find the header

消息“Can't find the 'libpq-fe.h header”意味着安装程序找不到这个头

  • Check that your Postgre installation contains development tools ("include" folder). Install postgre development tools in case of absence.
  • Check location of pg_config.exe. You need run installation like
    gem install pg -- --with-pg-config="C:/PROGRA~2/POSTGR~1/8.3/bin/pg_config.exe".
    Note that you need to use shortfolder names.
  • 检查您的 Postgre 安装是否包含开发工具(“include”文件夹)。在没有的情况下安装 postgre 开发工具。
  • 检查 pg_config.exe 的位置。您需要像
    gem install pg -- --with-pg-config="C:/PROGRA~2/POSTGR~1/8.3/bin/pg_config.exe".
    请注意,您需要使用文件夹名称。

To build a native extension for pg gem you need a ruby DevKit (http://rubyinstaller.org/downloads/)

要为 pg gem 构建本机扩展,您需要一个 ruby​​ DevKit ( http://rubyinstaller.org/downloads/)

I meet another problem:

我遇到了另一个问题:

D:\app1>rake test
(in D:/app1)
rake aborted!
no such file to load -- 1.9/pg_ext

D:\app1>rake test
(in D:/app1)
rake aborted!
no such file to load -- 1.9/pg_ext

In this case you need manually copy copy content of
C:\Ruby\192\lib\ruby\gems\1.9.1\gems\pg-0.10.0\lib\
to
C:\Ruby\192\lib\ruby\gems\1.9.1\gems\pg-0.10.0\lib\1.9

在这种情况下,您需要手动复制复制内容
C:\Ruby\192\lib\ruby\gems\1.9.1\gems\pg-0.10.0\lib\

C:\Ruby\192\lib\ruby\gems\1.9.1\gems\pg-0.10.0\lib\1.9

回答by Denis Gorbunov

Windows 7, PostgreSQL 8.4, Ruby 1.9.2:

Windows 7、PostgreSQL 8.4、Ruby 1.9.2:

subst X:\ "C:\Program Files\PostgreSQL.4"

gem install pg -- --with-pg=X:/

This installed it successfully.

这样就安装成功了。

回答by glebm

I had the same problem. You most likely have a perl installation in your path before PostgreSQL. The most common perl installation for Windows has an executable name pg_configin its bin which causes conflicts.

我有同样的问题。您很可能在 PostgreSQL 之前的路径中安装了 perl。Windows 最常见的 perl 安装pg_config在其 bin 中有一个可执行文件名,这会导致冲突。

pg v0.10.0 installs just fine with rubyinstaller + devkit as long as you specify paths without spaces (e.g. C:/PROGRA~) -- otherwise nmake chokes.

只要您指定不带空格的路径(例如 C:/PROGRA~),pg v0.10.0 就可以使用 ruby​​installer + devkit 进行安装——否则 nmake 会卡住。