无法在 Windows 上安装 pg gem

发布于 2024-10-05 10:32:44 字数 1051 浏览 3 评论 0原文

我有 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

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

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:

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(18

入画浅相思 2024-10-12 10:32:45

适用于 Linux 用户的 PsAdding。

我解决了安装 libpq-dev 时出现的错误。

PsAdding for linux users.

I solved this error installing libpq-dev.

墟烟 2024-10-12 10:32:45

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

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

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

CALL postgresql-path.bat

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

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

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

At the top of the msys.bat file I added

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.

早乙女 2024-10-12 10:32:45

为了解决这个问题,我首先必须按照安装说明安装 DevKit 。我必须复制(为了安全起见)然后将 operating_system.rb 文件删除到 \Ruby187\lib\ruby\site_ruby\1.8\rubygems\defaults 文件夹中,以便安装成功运行。

然后,我安装了 rake-compiler 和 rdoc gems:(

gem install rake-compiler
gem install rdoc

如果您对其中任何一个有问题,我建议自由使用 --platform=win32 配置选项)

一旦安装成功,最终安装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=C:\PostgreSQL\

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

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

Then, 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)

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

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

e.g.

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.

予囚 2024-10-12 10:32:45

“gem install pg”不起作用

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

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

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

这也应该适用于“Bash on Ubuntu on Windows”

"gem install pg" not working

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.

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

烟花易冷人易散 2024-10-12 10:32:45

首先在 Windows XP 上安装 ruby​​ DevKit

,并从 MSysGIT bash 终端执行以下操作
基于我的安装路径

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

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

我的 gem pg-0.10.1 已成功安装。

First install ruby DevKit

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

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

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

My gem pg-0.10.1 got installed successfully.

昔梦 2024-10-12 10:32:45

这看起来似乎是理所当然的事情,但我也犯了同样的错误,只是稍微有点扭曲。在构建找到标头后,它立即失败并声称无法找到 libpq。我最终推断出我正在尝试使用 32 位 ruby​​ 来构建 64 位 postgres 安装。安装 32 位 postgres 可以立即修复。只是想我会添加这个以防其他有相同错误的人偶然发现这个线程。

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.

蓦然回首 2024-10-12 10:32:45

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

  • 检查您的 Postgre 安装是否包含开发工具(“include”文件夹)。如果没有的话请安装postgre开发工具。
  • 检查 pg_config.exe 的位置。您需要运行安装
    gem install pg -- --with-pg-config="C:/PROGRA~2/POSTGR~1/8.3/bin/pg_config.exe"
    请注意,您需要使用文件夹名称。

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

我遇到另一个问题:

D:\app1>rake test
(在 D:/app1 中)
耙子中止!
没有要加载的文件——1.9/pg_ext

这种情况下你需要手动复制
的复制内容
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

The message "Can't find the 'libpq-fe.h header" means that installer can't find the 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 short folder names.

To build a native extension for pg gem you need a 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

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

醉殇 2024-10-12 10:32:45

谢谢路易斯! pg 0.9.0 安装得很好。

对于最新版本(0.10.0),您需要 devkit 和此命令“gem install pg -- --with pg-dir=path/to/your/postgresql/dir”

当我保留附加的“--”时,它给我一个错误:
“gem 安装 pg --with-pg-dir=C:/postgresql/9.0”

Thanks Luis! pg 0.9.0 installed just fine.

For the latest version (0.10.0) you need the devkit and this command "gem install pg -- --with pg-dir=path/to/your/postgresql/dir"

When I leave the additional "--" away, it gets me an error:
"gem install pg --with-pg-dir=C:/postgresql/9.0"

长发绾君心 2024-10-12 10:32:45

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

只要指定不带空格的路径(例如 C:/PROGRA~),pg v0.10.0 就可以与 ruby​​installer + devkit 一起安装,否则 nmake 会被阻塞。

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_config in its bin which causes conflicts.

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.

み格子的夏天 2024-10-12 10:32:45

Windows 7、PostgreSQL 8.4、Ruby 1.9.2:

subst X:\ "C:\Program Files\PostgreSQL\8.4"

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

安装成功。

Windows 7, PostgreSQL 8.4, Ruby 1.9.2:

subst X:\ "C:\Program Files\PostgreSQL\8.4"

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

This installed it successfully.

§对你不离不弃 2024-10-12 10:32:45

其他简单的方法,在 Windows 上

  1. 安装 postgresql ODBC。

  2. 从 pgqlODBC lib 目录复制 libpq.dll

  3. 将其粘贴到 PostGreSQL lib 目录

  4. 运行此命令(根据您的情况调整此命令中的 PostGreSQL 路径):

    gem install pg -- --with-pg-config="C:\Dev\Databases\PostgreSQL\9.0\bin\pg_config.exe"
    

Other easy way, on windows

  1. Install postgresql ODBC.

  2. Copy libpq.dll from the pgqlODBC lib directory

  3. Paste it into PostGreSQL lib directory

  4. Run this command (adapt the PostGreSQL path in this command, according to yours) :

    gem install pg -- --with-pg-config="C:\Dev\Databases\PostgreSQL\9.0\bin\pg_config.exe"
    
╰沐子 2024-10-12 10:32:45

每个 pacman 安装 postgresql:

ridk exec pacman -S mingw-w64-x86_64-postgresql

然后执行

bundle install

install postgresql per pacman:

ridk exec pacman -S mingw-w64-x86_64-postgresql

then do

bundle install
_畞蕅 2024-10-12 10:32:45

我也有同样的问题。

以下内容对我有用。希望这对您有帮助。

版本:

  • Windows 10 版本 10.0.19043.1165。
  • PostgreSQL 服务器 13。Ruby
  • DevKit 3.0.2-1 (x64)。

管理员提示符:C:\Ruby30-x64> subst X: "C:\Program Files\PostgreSQL\13\bin"

管理员提示符:C:\Ruby30-x64> gem install pg -- --with-pg-dir=X: --with-pg-include="c:\Program Files\PostgreSQL\13\include" --with-pg-lib="C:\Program Files \PostgreSQL\13\lib"

I had the same problem.

The following worked for me. Hope this helps to you.

Versions:

  • Windows 10 version 10.0.19043.1165.
  • PostgreSQL Server 13.
  • Ruby DevKit 3.0.2-1 (x64).

Administrator prompt: C:\Ruby30-x64> subst X: "C:\Program Files\PostgreSQL\13\bin"

Administrator prompt: C:\Ruby30-x64> gem install pg -- --with-pg-dir=X: --with-pg-include="c:\Program Files\PostgreSQL\13\include" --with-pg-lib="C:\Program Files\PostgreSQL\13\lib"

凑诗 2024-10-12 10:32:45

我遇到了同样的问题。我想使用 dbi 访问 postgres 数据库,并且必须安装 Pg。
我花了一天的时间才成功编译了该模块,其说明与该线程的其他帖子类似。但第二次我不得不这样做时,我找到了另一个解决方案:使用 ODBC。

  1. 安装 postgresql 的 ODBC 驱动程序 (http://www.postgresql.org/ftp/odbc/versions /
  2. 配置数据源(http://www.xtuple.org/SettingUpPostgresAndOdbc
  3. 安装 ruby​​ dbi 和 odbc gems

    gem 安装 dbi
    gem 安装 ruby​​-odbc
    gem 安装 dbd-odbc
    
  4. 连接到 postgres

    需要“dbi”
    dbh = DBI.connect('dbi:ODBC:DSN_NAME', '用户', 'PASS')
    

这对我在 Windows XP 32 位上使用 ruby​​ 1.9.1 有效。
此外,如果您已经在使用 DBI,那么除了 DBI.connect 行之外,这不会更改代码中的任何内容。

I ran into the same problem. I wanted to access a postgres database using dbi and had to install Pg.
It took me a day to successfully compile the module with instructions similar to the other posts of this thread. But the second time I had to do it, I found another solution: using ODBC.

  1. Install the ODBC driver for postgresql (http://www.postgresql.org/ftp/odbc/versions/)
  2. Configure the data source (http://www.xtuple.org/SettingUpPostgresAndOdbc)
  3. Install the ruby dbi and odbc gems

    gem install dbi
    gem install ruby-odbc
    gem install dbd-odbc
    
  4. Connect to postgres

    require 'dbi'
    dbh = DBI.connect('dbi:ODBC:DSN_NAME', 'USER', 'PASS')
    

This worked for me using ruby 1.9.1 on Windows XP 32 bit.
Also, this doesn't change anything in your code except the DBI.connect line, if you were already using DBI.

寂寞笑我太脆弱 2024-10-12 10:32:45

PostgreSQL 9.0:

gem install pg --platform=mswin32 --version=0.9.0 -- '--with-pg="C:\Progra~1\PostgreSQL\"'

注意单刻度封装。 (~1 表示“Program Files”,如果 PostgreSQL 位于 Win64 上的 Program Files (x86) 中,则更改为 ~2)

PostgreSQL 9.0:

gem install pg --platform=mswin32 --version=0.9.0 -- '--with-pg="C:\Progra~1\PostgreSQL\"'

note the single-tick encapsulation. (~1 signifies "Program Files", change to ~2 if PostgreSQL is in Program Files (x86) on Win64)

半步萧音过轻尘 2024-10-12 10:32:45

pg gem 的 0.13.0 版本开始,您应该能够使用如下所示的方式安装它:

subst X: "C:\Program Files\PostgreSQL\9.0"
gem install pg -- -- with-pg=X:
subst X: /D

然后您可以成功运行 bundle install 并在输出中看到以下行:

Using pg (0.13.0)

而不是错误。

As of version 0.13.0 of the pg gem, you should be able to install it using something like the following:

subst X: "C:\Program Files\PostgreSQL\9.0"
gem install pg -- -- with-pg=X:
subst X: /D

Then you can successfully run bundle install and see the following line in the output:

Using pg (0.13.0)

instead of the errors.

一页 2024-10-12 10:32:45

我明白了:

还有神奇的技巧:

is that you do not have this installed -- > postgres-devel

所以去得到它:

install postgresql-devel

就是这样......而不仅仅是 gem install pg 就这样了。

I got it:

AND THE MAGIC TRICK :

is that you do not have this installed -- > postgres-devel

so go get it :

install postgresql-devel

Thats all... than just gem install pg and there it goes.

↘人皮目录ツ 2024-10-12 10:32:44

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

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

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

不管怎样,如果你想安装gem,你需要安装一个构建环境。如果您使用的是 RubyInstaller,那么您需要 DevKit

安装 gem只需要您为 gem 安装提供附加选项(例如 --with-pg-dir

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

The message you're getting is a clear indication that you lack something for the correct installation of that 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.

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.

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

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

subst X: "C:\Program Files (x86)\PostgreSQL\8.3"
gem install pg -- --with-pg-dir=X:
subst X: /D
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文