2013-06-24 59 views
5

我知道這很簡單,但我無法弄清楚。我需要在Ruby中運行腳本,它需要Nokogiri。我在其他語言方面有一些經驗,但在Ruby中沒有。無法在Windows中安裝Ruby的Nokogiri

這裏是我的系統:

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

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

當我運行gem install nokogiri我得到這個錯誤:

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' 

很容易的。所以我遵循the link of above並做了第3步。但第4步說生成「config.yml」。所以我做了。現在該文件是一個帶有一些註釋的空白列表。由於上面的錯誤,我仍然無法安裝Nokogiri,而且我似乎無法使用DevKit。我所說的是,開發套件安裝中的步驟對我來說還不夠清楚。


更新現在說安裝引入nokogiri的失敗(根據步驟5的devkit工程:安裝JSON-1.8.0 1寶石安裝文件)

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 
+0

您絕對需要安裝DevKit以與Windows上的Nokogiri一起工作(除非您碰巧安裝了其他編譯​​工具,但似乎並非如此)。可以在這裏找到說明(https://github.com/oneclick/rubyinstaller/wiki/Development-Kit)。在DevKit安裝中,什麼不適合你? – PinnyM

+0

我推薦在這個時候使用ruby 1.9.3,2.0在windows上是一個冒險主張 – pguardiario

回答

13

更新:自1.6.2版本中,引入nokogiri現在確實支持64位版本的Ruby 2.0.0。 (請注意,它需要的libxml> = 2.6.21)

這裏的答案,如果你還需要安裝x86版本出於某種原因,或者如果你想了解如何安裝和使用的devkit建立一個寶石:


Nokogiri還不支持64位版本的Ruby 2.0.0。你可以閱讀關於它和follow the status here

但是Nokogiri 確實支持x86版本的ruby 2.0.0。您應該能夠在2.0.0 x86安裝上安裝gem。

手動安裝非常簡單。我更喜歡RailsInstaller,因爲我需要保持其他東西。操作方法如下:

  1. 下載並解壓縮所需版本的文件。確保download the correct version of DevKit適用於2.0.0的x86版本。

  2. 解決您的路徑:請確保您的路徑包括目錄,以正確的紅寶石,寶石,並顯示目錄的devkit: 假設你安裝了Ruby 2.0.0的x86版本到C:\rubies\ruby-2-0-0-x86和相關的devkit到C:\rubies\DevKit-xxxx-x86您需要將這些目錄包含在PATH中:

    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

  3. 將DevKit注入右邊的ruby install:一旦你安裝了ruby並且可以獲得輸入ruby -v後輸入正確的信息,然後運行ruby dk.rb init - 這將使DevKit將&'注入'設置爲正確的ruby版本。 (注:我總是以編輯製作並放在正確的路徑紅寶石安裝我想config.yml文件。別擔心,如果你需要做的。)

0

是...降級到1.9.3工作。 Tnx求助。我把這裏的總結:

  • 安裝Ruby 1.9.3(不要更改安裝名稱ex.RubyLang或
    配置不能自動找到它)

  • 安裝的devkit(按照安裝的devkit步驟)

  • 安裝引入nokogiri

0

我是不是能夠在Windows 7上爲Ruby 2.0安裝x64 Nokogiri,但binary gem似乎正在工作。