尝试安装Rmagick后无法运行rails服务器

时间:2013-03-09 23:59:41

标签: ruby-on-rails ruby-on-rails-3 rmagick

我在Windows上,我从这里下载并安装了rmagick-win32 RMagick-2.12.0-ImageMagick-6.5.6-8-Q8(http://rubyforge.org/frs/?group_id=12&release_id=42049),我使用'gem install rmagick解压缩并安装“

当我尝试运行rails时,收到此错误消息

C:\Users\Me\Desktop\sample_app>rails s
←[31mCould not find gem 'rmagick (>= 0) x86-mingw32' in any of the gem sources l
isted in your Gemfile.←[0m
←[33mRun `bundle install` to install missing gems.←[0m

所以我尝试捆绑安装或捆绑更新然后我得到这个(我拿出了宝石的完整列表以节省空间):

C:\Users\Me\Desktop\sample_app>bundle update

Fetching source index for https://rubygems.org/
Installing rmagick (2.13.2) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension
.

        C:/RailsInstaller/Ruby1.9.3/bin/ruby.exe extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for stdint.h... *** 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:/RailsInstaller/Ruby1.9.3/bin/ruby
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler
 failed to generate an executable file. (RuntimeError)
You have to install development tools first.
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/mkmf.rb:506:in `try_cpp'

        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/mkmf.rb:931:in `block in
 have_header'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/mkmf.rb:790:in `block in
 checking_for'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/mkmf.rb:284:in `block (2
 levels) in postpone'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/mkmf.rb:254:in `open'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/mkmf.rb:284:in `block in
 postpone'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/mkmf.rb:254:in `open'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/mkmf.rb:280:in `postpone
'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/mkmf.rb:789:in `checking
_for'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/mkmf.rb:930:in `have_hea
der'
        from extconf.rb:194:in `<main>'


Gem files will remain installed in C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9
.1/gems/rmagick-2.13.2 for inspection.
Results logged to C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rmagick-2
.13.2/ext/RMagick/gem_make.out
An error occured while installing rmagick (2.13.2), and Bundler cannot continue.

Make sure that `gem install rmagick -v '2.13.2'` succeeds before bundling.

然后我下载了rmagick 2.13.2并将其放入同一文件夹并运行“gem install rmagick -v'2.13.2',但我收到失败的错误:无法再次构建gem原生扩展

我正在尝试安装2.13.2,但我找不到任何相关信息。任何人都知道这是否是问题以及如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

Windows上的RMagick很棘手。在我上Windows的过程中,我设法找到了两个解决同一问题的解决方案。

简单解决方案

将以下内容添加到您的Gemfile中。它还将考虑其他平台。

if RUBY_PLATFORM =~ /(win|w)32$/
  gem 'rmagick', '2.12.0', :path => 'vendor/gems/rmagick-2.12.0-x86-mswin32', :require => 'RMagick'
else
  gem 'rmagick', :require => 'RMagick'
end

然后,使用:

将gem解压缩到vendors/gems/
gem unpack rmagick-2.12.0-x86-mswin32.gem vendors/gems/

更好的解决方案

我发现可以在Windows上编译RMagick gem。在执行此解决方案之前,请确保已安装DevKit

我创建了a batch file,它将ImageMagick的目录映射到X:\,并为gem命令提供参数,以查找构建RMagick所需文件的位置。这种映射是必要的,因为配置选项不知道如何处理路径中的空格。

您可以使用以下命令将ImageMagick的目录映射到X:\并编译并安装gem。

subst X: "C:\Program Files (x86)\ImageMagick-6.7.6-Q16"
gem install rmagick --platform=ruby -- --with-opt-lib="X:\lib" --with-opt-include="X:\include"
subst X: /D

如果您安装的版本不是6.7.6-Q16,或者您不在64位Windows上,则需要编辑路径。

使用此解决方案安装gem之后,您现在应该只能在Gemfile中捆绑gem 'rmagick', :require => 'RMagick'

答案 1 :(得分:0)

在Windows上,你需要Ruby的DevKit来编译本机C扩展(包括一些宝石)。