安装Rmagick: ' require':没有要加载的文件- Rmagick (LoadError)

时间:2023-01-19 14:46:50

When I run the command ruby billede.rb in my lib folder in rails I get the error:

当我运行ruby billede命令时。在rails的lib文件夹中,我得到了一个错误:

C:\Rails\myapp\lib>ruby billede.rb
C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require':
no such file to load -- RMagick (LoadError)
        from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:i
n `require'
        from billede.rb:2:in `<main>'

My Billede.rb:

我的Billede.rb:

class Billede
require 'rubygems'
require 'RMagick'

if !ARGV[0]
    puts "Usage: watermark /image.png"
    exit
end

image = Magick::Image.read(ARGV[0]).first

mark = Magick::Image.new(image.columns, image.rows)

gc = Magick::Draw.new
gc.gravity = Magick::CenterGravity
gc.pointsize = 32
gc.font_family = "Helvetica"
gc.font_weight = Magick::BoldWeight
gc.stroke = 'none'
gc.annotate(mark, 0, 0, 0, 0, "Watermark\nby\nRMagick")

mark = mark.shade(true, 310, 30)

image.composite!(mark, Magick::CenterGravity, Magick::HardLightCompositeOp)

out = ARGV[0].sub(/\./, "-wm.")
puts "Writing #{out}"
image.write(out)
end

I have installed RMagick.

我已经安装了RMagick。

Update when installing the gem.

安装gem时更新。

In my gemfile I have:

在我的gemfile里,我有:

gem "rmagick", :require => 'RMagick'

When running bundle install:

运行时包安装:

C:\Rails\myapp>bundle install
Fetching source index for http://rubygems.org/
Using rake (0.9.1)
Using abstract (1.0.0)
Using activesupport (3.0.9)
Using builder (2.1.2)
Using i18n (0.5.0)
Using activemodel (3.0.9)
Using erubis (2.6.6)
Using rack (1.2.4)
Using rack-mount (0.6.14)
Using rack-test (0.5.7)
Using tzinfo (0.3.30)
Using actionpack (3.0.9)
Using mime-types (1.16)
Using polyglot (0.3.2)
Using treetop (1.4.10)
Using mail (2.2.19)
Using actionmailer (3.0.9)
Using arel (2.0.10)
Using activerecord (3.0.9)
Using activeresource (3.0.9)
Using addressable (2.2.6)
Using bundler (1.0.18)
Using multipart-post (1.1.4)
Using faraday (0.7.6)
Using friendly_id (4.0.0)
Using hashie (1.2.0)
Using json (1.6.1)
Using multi_json (1.0.4)
Using mysql (2.8.1)
Using oauth2 (0.5.2)
Using omniauth (1.0.2)
Using omniauth-oauth2 (1.0.0)
Using omniauth-facebook (1.2.0)
Using rdoc (3.10)
Using thor (0.14.6)
Using railties (3.0.9)
Using rails (3.0.9)
Using rest-client (1.6.7)
Installing rmagick (2.13.1) with native extensions C:/Ruby192/lib/ruby/site_ruby
/1.9.1/rubygems/installer.rb:552:in `rescue in block in build_extensions': ERROR
: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

        C:/Ruby192/bin/ruby.exe extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for stdint.h... yes
checking for sys/types.h... yes
checking for wand/MagickWand.h... yes
checking for snprintf() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdin
t.h,sys/types.h,wand/MagickWand.h... yes
checking for AcquireImage() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,s
tdint.h,sys/types.h,wand/MagickWand.h... yes
checking for AffinityImage() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,
stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for AffinityImages() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h
,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for AutoGammaImageChannel() in assert.h,ctype.h,stdio.h,stdlib.h,math.h
,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for AutoLevelImageChannel() in assert.h,ctype.h,stdio.h,stdlib.h,math.h
,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for BlueShiftImage() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h
,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for ConstituteComponent*() in assert.h,ctype.h,stdio.h,stdlib.h,
math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for DeskewImage() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,st
dint.h,sys/types.h,wand/MagickWand.h... yes
checking for EncipherImage() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,
stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for EqualizeImageChannel() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,
time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for FloodfillPaintImage() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,t
ime.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for FunctionImageChannel() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,
time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for GetAuthenticIndexQueue() in assert.h,ctype.h,stdio.h,stdlib.h,math.
h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for GetAuthenticPixels() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,ti
me.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for GetImageAlphaChannel() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,
time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for GetVirtualPixels() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time
.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for LevelImageColors() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time
.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for LevelColorsImageChannel() in assert.h,ctype.h,stdio.h,stdlib.h,math
.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for LevelizeImageChannel() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,
time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for LiquidRescaleImage() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,ti
me.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for MagickLibAddendum() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,tim
e.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for OpaquePaintImageChannel() in assert.h,ctype.h,stdio.h,stdlib.h,math
.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for QueueAuthenticPixels() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,
time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for RemapImage() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,std
int.h,sys/types.h,wand/MagickWand.h... yes
checking for RemoveImageArtifact() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,t
ime.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for SelectiveBlurImageChannel() in assert.h,ctype.h,stdio.h,stdlib.h,ma
th.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for SetImageAlphaChannel() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,
time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for SetImageArtifact() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time
.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for SetMagickMemoryMethods() in assert.h,ctype.h,stdio.h,stdlib.h,math.
h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for SparseColorImage() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time
.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for SyncAuthenticPixels() in assert.h,ctype.h,stdio.h,stdlib.h,math.h,t
ime.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for TransparentPaintImage() in assert.h,ctype.h,stdio.h,stdlib.h,math.h
,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for TransparentPaintImageChroma() in assert.h,ctype.h,stdio.h,stdlib.h,
math.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for QueryMagickColorname() new signature... yes
checking for Image.type in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdin
t.h,sys/types.h,wand/MagickWand.h... yes
checking for DrawInfo.kerning in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h
,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for DrawInfo.interline_spacing in assert.h,ctype.h,stdio.h,stdlib.h,mat
h.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for DrawInfo.interword_spacing in assert.h,ctype.h,stdio.h,stdlib.h,mat
h.h,time.h,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for DitherMethod in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,std
int.h,sys/types.h,wand/MagickWand.h... yes
checking for MagickFunction in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,s
tdint.h,sys/types.h,wand/MagickWand.h... yes
checking for ImageLayerMethod in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h
,stdint.h,sys/types.h,wand/MagickWand.h... yes
checking for long double in assert.h,ctype.h,stdio.h,stdlib.h,math.h,time.h,stdi
nt.h,sys/types.h,wand/MagickWand.h... yes
checking for AlphaChannelType.CopyAlphaChannel... yes
checking for AlphaChannelType.BackgroundAlphaChannel... yes
checking for CompositeOperator.BlurCompositeOp... yes
checking for CompositeOperator.DistortCompositeOp... yes
checking for CompositeOperator.LinearBurnCompositeOp... yes
checking for CompositeOperator.LinearDodgeCompositeOp... yes
checking for CompositeOperator.MathematicsCompositeOp... yes
checking for CompositeOperator.PegtopLightCompositeOp... yes
checking for CompositeOperator.PinLightCompositeOp... yes
checking for CompositeOperator.VividLightCompositeOp... yes
checking for CompressionType.DXT1Compression... yes
checking for CompressionType.DXT3Compression... yes
checking for CompressionType.DXT5Compression... yes
checking for CompressionType.ZipSCompression... yes
checking for CompressionType.PizCompression... yes
checking for CompressionType.Pxr24Compression... yes
checking for CompressionType.B44Compression... yes
checking for CompressionType.B44ACompression... yes
checking for DistortImageMethod.BarrelDistortion... yes
checking for DistortImageMethod.BarrelInverseDistortion... yes
checking for DistortImageMethod.BilinearForwardDistortion... yes
checking for DistortImageMethod.BilinearReverseDistortion... yes
checking for DistortImageMethod.DePolarDistortion... yes
checking for DistortImageMethod.PolarDistortion... yes
checking for DistortImageMethod.PolynomialDistortion... yes
checking for DistortImageMethod.ShepardsDistortion... yes
checking for DitherMethod.NoDitherMethod... yes
checking for FilterTypes.KaiserFilter... yes
checking for FilterTypes.WelshFilter... yes
checking for FilterTypes.ParzenFilter... yes
checking for FilterTypes.LagrangeFilter... yes
checking for FilterTypes.BohmanFilter... yes
checking for FilterTypes.BartlettFilter... yes
checking for FilterTypes.SentinelFilter... yes
checking for MagickEvaluateOperator.PowEvaluateOperator... yes
checking for MagickEvaluateOperator.LogEvaluateOperator... yes
checking for MagickEvaluateOperator.ThresholdEvaluateOperator... yes
checking for MagickEvaluateOperator.ThresholdBlackEvaluateOperator... yes
checking for MagickEvaluateOperator.ThresholdWhiteEvaluateOperator... yes
checking for MagickEvaluateOperator.GaussianNoiseEvaluateOperator... yes
checking for MagickEvaluateOperator.ImpulseNoiseEvaluateOperator... yes
checking for MagickEvaluateOperator.LaplacianNoiseEvaluateOperator... yes
checking for MagickEvaluateOperator.MultiplicativeNoiseEvaluateOperator... yes
checking for MagickEvaluateOperator.PoissonNoiseEvaluateOperator... yes
checking for MagickEvaluateOperator.UniformNoiseEvaluateOperator... yes
checking for MagickEvaluateOperator.CosineEvaluateOperator... yes
checking for MagickEvaluateOperator.SineEvaluateOperator... yes
checking for MagickEvaluateOperator.AddModulusEvaluateOperator... yes
checking for MagickFunction.ArcsinFunction... yes
checking for MagickFunction.ArctanFunction... yes
checking for MagickFunction.PolynomialFunction... yes
checking for MagickFunction.SinusoidFunction... yes
checking for ImageLayerMethod.FlattenLayer... yes
checking for ImageLayerMethod.MergeLayer... yes
checking for ImageLayerMethod.MosaicLayer... yes
checking for ImageLayerMethod.TrimBoundsLayer... yes
checking for VirtualPixelMethod.HorizontalTileVirtualPixelMethod... yes
checking for VirtualPixelMethod.VerticalTileVirtualPixelMethod... yes
checking for VirtualPixelMethod.HorizontalTileEdgeVirtualPixelMethod... yes
checking for VirtualPixelMethod.VerticalTileEdgeVirtualPixelMethod... yes
checking for VirtualPixelMethod.CheckerTileVirtualPixelMethod... yes
checking for ruby/io.h... yes
checking for rb_frame_this_func() in ruby.h,ruby/io.h... yes
creating extconf.h
creating Makefile


======================================================================
Wed 25Apr12 14:10:35
This installation of RMagick 2.13.1 is configured for
Ruby 1.9.2 (i386-mingw32) and ImageMagick 6.7.6
======================================================================



make


Gem files will remain installed in C:/Ruby192/lib/ruby/gems/1.9.1/gems/rmagick-2
.13.1 for inspection.
Results logged to C:/Ruby192/lib/ruby/gems/1.9.1/gems/rmagick-2.13.1/ext/RMagick
/gem_make.out
        from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:530:in `b
lock in build_extensions'
        from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:505:in `e
ach'
        from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:505:in `b
uild_extensions'
        from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:180:in `i
nstall'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.18/lib/bundler/sour
ce.rb:101:in `block in install'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.18/lib/bundler/ruby
gems_integration.rb:78:in `preserve_paths'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.18/lib/bundler/sour
ce.rb:91:in `install'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.18/lib/bundler/inst
aller.rb:58:in `block (2 levels) in run'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.18/lib/bundler/ruby
gems_integration.rb:93:in `with_build_args'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.18/lib/bundler/inst
aller.rb:57:in `block in run'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.18/lib/bundler/inst
aller.rb:49:in `run'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.18/lib/bundler/inst
aller.rb:8:in `install'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.18/lib/bundler/cli.
rb:220:in `install'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.18/lib/bundler/vend
or/thor/task.rb:22:in `run'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.18/lib/bundler/vend
or/thor/invocation.rb:118:in `invoke_task'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.18/lib/bundler/vend
or/thor.rb:263:in `dispatch'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.18/lib/bundler/vend
or/thor/base.rb:386:in `start'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.18/bin/bundle:13:in
 `<top (required)>'
        from C:/Ruby192/bin/bundle:19:in `load'
        from C:/Ruby192/bin/bundle:19:in `<main>'

C:\Rails\myapp>

3 个解决方案

#1


2  

If you are using Bundler (when you are using Rails you are using Bundler, too) you need to add RMagick to your Gemfile. Bundler only loads the bundled gems into your environment.

如果您正在使用Bundler(当您使用Rails时,您也在使用Bundler),那么您需要将RMagick添加到Gemfile中。Bundler只将绑定的宝石装载到您的环境中。

Gemfile

Gemfile

source :rubygems

# loads of other stuff

gem 'rmagick'

then run

然后运行

bundle install

and you should be good to go

你应该走了

#2


0  

External scripts in your rails project should be run as follows:

rails项目中的外部脚本应该如下所示:

bundle exec lib/billede.rb <params>

(make sure you have gem 'RMagick' in the Gemfile)

(确保你的宝石文件中有宝石“RMagick”。)

this way in case of any dependency issues you'll get more descriptive output.

这样,如果有任何依赖项问题,您将得到更多描述性的输出。

#3


0  

You need to install imagemagic first:

您需要先安装imagemagic:

sudo apt-get install libmagickwand-dev imagemagick

Then add the ruby wrapper to your gemfile:

然后将ruby包装器添加到gemfile中:

gem 'rmagick'

And finally tell Bundler to download rmagic:

最后告诉Bundler下载rmagic:

bundle install

#1


2  

If you are using Bundler (when you are using Rails you are using Bundler, too) you need to add RMagick to your Gemfile. Bundler only loads the bundled gems into your environment.

如果您正在使用Bundler(当您使用Rails时,您也在使用Bundler),那么您需要将RMagick添加到Gemfile中。Bundler只将绑定的宝石装载到您的环境中。

Gemfile

Gemfile

source :rubygems

# loads of other stuff

gem 'rmagick'

then run

然后运行

bundle install

and you should be good to go

你应该走了

#2


0  

External scripts in your rails project should be run as follows:

rails项目中的外部脚本应该如下所示:

bundle exec lib/billede.rb <params>

(make sure you have gem 'RMagick' in the Gemfile)

(确保你的宝石文件中有宝石“RMagick”。)

this way in case of any dependency issues you'll get more descriptive output.

这样,如果有任何依赖项问题,您将得到更多描述性的输出。

#3


0  

You need to install imagemagic first:

您需要先安装imagemagic:

sudo apt-get install libmagickwand-dev imagemagick

Then add the ruby wrapper to your gemfile:

然后将ruby包装器添加到gemfile中:

gem 'rmagick'

And finally tell Bundler to download rmagic:

最后告诉Bundler下载rmagic:

bundle install