无法在 Windows 中为 Ruby 安装 Nokogiri [英] Can't install Nokogiri for Ruby in Windows

查看:42
本文介绍了无法在 Windows 中为 Ruby 安装 Nokogiri的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这很简单,但我就是想不通.我需要在 Ruby 中运行一个脚本,它需要 Nokogiri.我确实在其他语言方面有一些经验,但在 Ruby 方面没有.

I know this is simple but I just can't figure it out. I need to run a script in Ruby and it requires Nokogiri. I do have some experience in other languages but not in Ruby.

这是我的系统:

Ruby 2.0.0-p195 (x64) 已安装@C:\Programs\RubyLanguage

Ruby 2.0.0-p195 (x64) is installed @ C:\Programs\RubyLanguage

Ruby 开发工具包 (mingw64-64-4.7.2-20130224-1432) 安装在@C:\Programs\RubyDevKit

Ruby Development Kit (mingw64-64-4.7.2-20130224-1432) is installed @ C:\Programs\RubyDevKit

当我运行 gem install nokogiri 时出现此错误:

When I run gem install nokogiri I get this error:

    ERROR:  Error installing nokogiri:
        The 'nokogiri' native gem requires installed build tools.

Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'

很简单.所以我跟着上面的链接并做了第3步.但是第4步说生成config.yml".所以我做了.现在该文件是一个带有一些注释的空列表.由于上述错误,我仍然无法安装 Nokogiri 并且我似乎无法使用 DevKit .我要说的是,Development Kit 安装中的步骤对我来说还不够清楚.

Easy enough. So I followed the link of above and did to step 3. However step 4 says generate "config.yml". So I did. Now the file is an empty list with some comments. I still can't install Nokogiri because of error above and I don't seem to get anywhere with DevKit . What I am saying is that the steps in the Development Kit installation is not clear enough for me.

更新现在说 Nokogiri 安装失败(DevKit Works 根据第 5 步:为 json-1.8.0 安装文档安装了 1 个 gem )

Update it now says installation of Nokogiri failed ( DevKit Works according to step 5 : Installing documentation for json-1.8.0 1 gem installed )

mkmf.log: package configuration for libxslt is not found
package configuration for libxml-2.0 is not found
package configuration for libiconv is not found
find_header: checking for libxml/parser.h... -------------------- no

"x86_64-w64-mingw32-gcc -o conftest.exe -IC:/Programs/RubyLanguage/include/ruby-2.0.0/x64-mingw32 -IC:/Programs/RubyLanguage/include/ruby-2.0.0/ruby/backward -IC:/Programs/RubyLanguage/include/ruby-2.0.0 -I. -IC:/Programs/RubyLanguage/include/libxml2 -IC:/Programs/RubyLanguage/include -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D_FILE_OFFSET_BITS=64   -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration  -DXP_WIN -DXP_WIN32 -DUSE_INCLUDED_VASPRINTF -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline conftest.c  -L. -LC:/Programs/RubyLanguage/lib -LC:/Programs/RubyLanguage/lib -L.      -lx64-msvcrt-ruby200  -lshell32 -lws2_32 -limagehlp -lshlwapi   "
In file included from C:/Programs/RubyLanguage/include/ruby-2.0.0/ruby/defines.h:153:0,
                 from C:/Programs/RubyLanguage/include/ruby-2.0.0/ruby/ruby.h:70,
                 from C:/Programs/RubyLanguage/include/ruby-2.0.0/ruby.h:33,
                 from conftest.c:1:
C:/Programs/RubyLanguage/include/ruby-2.0.0/ruby/win32.h: In function 'rb_w32_pow':
C:/Programs/RubyLanguage/include/ruby-2.0.0/ruby/win32.h:776:16: warning: conversion to 'double' from 'long double' may alter its value [-Wconversion]
In file included from C:/Programs/RubyLanguage/include/ruby-2.0.0/ruby.h:33:0,
                 from conftest.c:1:
C:/Programs/RubyLanguage/include/ruby-2.0.0/ruby/ruby.h: In function 'rb_float_value':
C:/Programs/RubyLanguage/include/ruby-2.0.0/ruby/ruby.h:777:6: warning: negative integer implicitly converted to unsigned type [-Wsign-conversion]
C:/Programs/RubyLanguage/include/ruby-2.0.0/ruby/ruby.h:777:6: warning: negative integer implicitly converted to unsigned type [-Wsign-conversion]
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <winsock2.h>
4: #include <windows.h>
5: int main(int argc, char **argv)
6: {
7:   return 0;
8: }
/* end */

"x86_64-w64-mingw32-gcc -E -IC:/Programs/RubyLanguage/include/ruby-2.0.0/x64-mingw32 -IC:/Programs/RubyLanguage/include/ruby-2.0.0/ruby/backward -IC:/Programs/RubyLanguage/include/ruby-2.0.0 -I. -IC:/Programs/RubyLanguage/include/libxml2 -IC:/Programs/RubyLanguage/include -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D_FILE_OFFSET_BITS=64   -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration  -DXP_WIN -DXP_WIN32 -DUSE_INCLUDED_VASPRINTF -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline  conftest.c -o conftest.i"
conftest.c:5:27: fatal error: libxml/parser.h: No such file or directory
compilation terminated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <winsock2.h>
4: #include <windows.h>
5: #include <libxml/parser.h>
/* end */

CMD 日志

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\SEPEHR>gem install nokogiri
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing nokogiri:
        ERROR: Failed to build gem native extension.

    C:/Programs/RubyLanguage/bin/ruby.exe extconf.rb
checking for libxml/parser.h... no
-----
libxml2 is missing.  please visit http://nokogiri.org/tutorials/installing_nokog
iri.html for help with installing dependencies.
-----
*** 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:/Programs/RubyLanguage/bin/ruby
        --with-zlib-dir
        --without-zlib-dir
        --with-zlib-include
        --without-zlib-include=${zlib-dir}/include
        --with-zlib-lib
        --without-zlib-lib=${zlib-dir}/lib
        --with-iconv-dir
        --without-iconv-dir
        --with-iconv-include
        --without-iconv-include=${iconv-dir}/include
        --with-iconv-lib
        --without-iconv-lib=${iconv-dir}/lib
        --with-xml2-dir
        --without-xml2-dir
        --with-xml2-include
        --without-xml2-include=${xml2-dir}/include
        --with-xml2-lib
        --without-xml2-lib=${xml2-dir}/lib
        --with-xslt-dir
        --without-xslt-dir
        --with-xslt-include
        --without-xslt-include=${xslt-dir}/include
        --with-xslt-lib
        --without-xslt-lib=${xslt-dir}/lib
        --with-libxslt-config
        --without-libxslt-config
        --with-pkg-config
        --without-pkg-config
        --with-libxml-2.0-config
        --without-libxml-2.0-config
        --with-pkg-config
        --without-pkg-config
        --with-libiconv-config
        --without-libiconv-config
        --with-pkg-config
        --without-pkg-config


Gem files will remain installed in C:/Programs/RubyLanguage/lib/ruby/gems/2.0.0/
gems/nokogiri-1.6.0 for inspection.
Results logged to C:/Programs/RubyLanguage/lib/ruby/gems/2.0.0/gems/nokogiri-1.6
.0/ext/nokogiri/gem_make.out

推荐答案

更新:从 1.6.2 版开始,Nokogiri 现在确实支持 64 位版本的 Ruby 2.0.0.(注意它需要 libxml >= 2.6.21 )

Update: As of version 1.6.2, Nokogiri now does support the 64-bit version of Ruby 2.0.0. (Note that it requires libxml >= 2.6.21 )

如果您出于某种原因仍然需要安装 x86 版本,或者您想了解如何使用 DevKit 安装和构建 gem,这里是答案:

Here's the answer if you still need to install the x86 version for some reason or if you want to understand how to install and build a gem using DevKit:

Nokogiri 尚不支持64 位 Ruby 2.0.0 版本.您可以阅读它和关注这里的状态.

Nokogiri does not yet support the 64-bit version of Ruby 2.0.0. You can read about it and follow the status here.

但是 Nokogiri 确实支持 x86 版本的 ruby​​ 2.0.0.您应该能够在 2.0.0 x86 安装中安装 gem.

But Nokogiri does support the x86 version of ruby 2.0.0. You should be able to install the gem in on 2.0.0 x86 install.

手动安装非常容易.我更喜欢 RailsInstaller,因为我需要按原样维护其他东西.方法如下:

It's pretty easy to hand-install. I prefer that over RailsInstaller because I need to maintain other things as they are. Here's how:

  1. 下载并解压缩所需版本的文件.请务必下载适用于 x86 版本 2.0.0 的正确版本的 DevKit.

修复您的路径:确保您的路径包含正确的 ruby​​、gem 和 DevKit 目录:假设您将 x86 版本的 ruby​​ 2.0.0 安装到 C:\rubies\ruby-2-0-0-x86 并将关联的 DevKit 安装到 C:\rubies\DevKit-xxxx-x86 你需要在你的 PATH 中包含这些目录:

Fix your path: Make sure your path includes the directories to the right ruby, gem, and DevKit dirs: Assume you installed the x86 version of ruby 2.0.0 into C:\rubies\ruby-2-0-0-x86 and the associated DevKit into C:\rubies\DevKit-xxxx-x86 you will need to include these directories in your PATH:

C:\rubies\ruby-2-0-0-x86\binC:\rubies\ruby-2-0-0-x86\lib\ruby\gems\2.0.0C:\rubies\DevKit-xxxx-x86\bin

C:\rubies\ruby-2-0-0-x86\bin C:\rubies\ruby-2-0-0-x86\lib\ruby\gems\2.0.0 C:\rubies\DevKit-xxxx-x86\bin

将 DevKit 注入正确的 ruby​​ 安装:一旦你安装了 ruby​​ 并且当你输入 ruby -v 时可以获得正确的信息,然后运行 ​​ruby dk.rb init -- 这将设置 DevKit &注入"到正确的 ruby​​ 版本中.(注意,我总是必须编辑生成的 config.yml 文件,并将其放入我想要的 ruby​​ 安装的正确路径中.如果您需要这样做,请不要担心.)>

Inject DevKit into the right ruby install: Once you have ruby installed and can get the correct info when you type ruby -v, then run ruby dk.rb init -- which will get DevKit set up & 'injected' into the correct ruby version. (N.B. I always have to edit the config.yml file that is produced and put in the correct path to the ruby installation I want. Don't sweat it if you need to do that.)

这篇关于无法在 Windows 中为 Ruby 安装 Nokogiri的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆