RMagick安装:找不到MagickWand.h

更新RMagick和Imagemagick是一个痛苦的经历 。 我更新了我的Mac上的Imagemagick版本(MacOS El Capitan 10.11.5版本),用Ruby 2.3中的一个项目的自制软件更新到6.9.5-9

 $ convert --version Version: ImageMagick 6.9.5-9 Q16 x86_64 2016-09-09 

现在,Ruby 1.8.7中的一个较老的项目拒绝使用错误消息“这个RMagick的安assembly置了ImageMagick 6.8.9,但ImageMagick 6.9.5-9正在使用”。 因此,我卸载了“rmagick”,但不能再次安装

 $ gem install rmagick -v 2.16.0 Building native extensions. This could take a while... ERROR: Error installing rmagick: ERROR: Failed to build gem native extension. checking for /usr/local/opt/gcc46/bin/gcc-4.6... yes checking for Magick-config... yes checking for outdated ImageMagick version (<= 6.4.9)... no checking for presence of MagickWand API (ImageMagick version >= 6.9.0)... no checking for Ruby version >= 1.8.5... yes checking for stdint.h... no checking for sys/types.h... no checking for wand/MagickWand.h... no Can't install RMagick 2.16.0. Can't find MagickWand.h. 

如果无法安装,则整个应用程序无法启动。 我尝试了所有从这里得到的答案,并没有一个在MacOS上工作:-(我用homebrew重新安装了imagemagick和pkg-config,并尝试了各种版本的RMagick,但没有成功。2.16.0是目前RMagick的最新版本。

MagicWand似乎用于ImageMagick版本> 6.9,它可以在机器上find:

 find /usr/local -name MagickWand.h => /usr/local/Cellar/imagemagick/6.9.5-9_1/include/ImageMagick-6/wand/MagickWand.h find /usr/local -name MagickWand.pc => /usr/local/Cellar/imagemagick/6.9.5-9_1/lib/pkgconfig/MagickCore.pc 

即使我在gem安装过程中指定了这些path(与上面相同的错误),它也不起作用:-(

 C_INCLUDE_PATH=/usr/local/Cellar/imagemagick/6.9.5-9_1/include/ImageMagick-6 PKG_CONFIG_PATH=/usr/local/lib/pkgconfig gem install rmagick 

更新:

这个错误只发生在Ruby 1.8.7上,可以为Ruby 2.0和Ruby 2.3安装RMagick。 Ruby 1.8.7和ImageMagick 6.9.5似乎不兼容。

  • Ruby 1.8.7 x
  • Ruby 2.0.0✓
  • Ruby 2.3.1✓

在Mac OSX Sierra中,为了解决这个问题,我必须做到以下几点:

 brew unlink imagemagick brew install imagemagick@6 && brew link imagemagick@6 --force 

imagemagick@6keg-only ,所以你需要强制链接。

我有与ImageMagick 7.0.4-4相同的问题。 正确的解决办法是安装imagemagick@6 。 我发现https://github.com/Homebrew/homebrew-core/pull/8756有用,如果你不小心删除了;imagemagick@6或者从来没有安装在第一位。

ImageMagick 7中的许多事情已经改变了,像这样的path: include/.../wand ,而wand/MagickWand.h MagickWand.h目前在rmagic gem中是硬连线的。 在我的情况下,由于项目比较老,所以无法更新gem。 所以我最终安装了一个老版本的ImageMagic。

您可以安装6.xx中的最新版本:

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/6f014f2b7f1f9e618fd5c0ae9c93befea671f8be/Formula/imagemagick.rb

您也可以将其固定在以后使用: brew pin imagemagick

macOs Sierra:

 brew uninstall imagemagick brew install imagemagick@6 brew link imagemagick@6 --force 

ImageMagick 7.0.4-4改变了我的一些东西。 wand/MagickWand.h再也找不到了:

 % brew unlink imagemagick && brew link imagemagick Unlinking /usr/local/Cellar/imagemagick/7.0.4-4... 71 symlinks removed Linking /usr/local/Cellar/imagemagick/7.0.4-4... 71 symlinks created % gem install rmagick Building native extensions. This could take a while... ERROR: Error installing rmagick: ERROR: Failed to build gem native extension. /Users/holger/.rbenv/versions/2.2.2/bin/ruby -r ./siteconf20170116-21103-1aikaka.rb extconf.rb checking for clang... yes checking for Magick-config... no checking for pkg-config... yes checking for outdated ImageMagick version (<= 6.4.9)... no checking for presence of MagickWand API (ImageMagick version >= 6.9.0)... no checking for Ruby version >= 1.8.5... yes checking for stdint.h... yes checking for sys/types.h... yes checking for wand/MagickWand.h... no Can't install RMagick 2.16.0. Can't find MagickWand.h. 

我在我的系统上仍然有ImageMagick 6.9.7-3,并改变了

 % brew switch imagemagick 6.9.7-3 Cleaning /usr/local/Cellar/imagemagick/6.9.6-6 Cleaning /usr/local/Cellar/imagemagick/6.9.7-0 Cleaning /usr/local/Cellar/imagemagick/6.9.7-1 Cleaning /usr/local/Cellar/imagemagick/6.9.7-3 Cleaning /usr/local/Cellar/imagemagick/7.0.4-4 75 links created for /usr/local/Cellar/imagemagick/6.9.7-3 

之后,我可以安装rmagick没有麻烦:

 % gem install rmagick Building native extensions. This could take a while... Successfully installed rmagick-2.16.0 1 gem installed 
 $ brew remove imagemagick && brew install imagemagick $ brew uninstall pkg-config && brew install pkg-config $ brew unlink pkg-config && brew link pkg-config $ gem install rmagick 

我还没有声望留下这个评论改善另一个答案,但@ Evgeniy28的答案只有在安装pkg-config之后才为我工作,pkg-config并不是默认安装在新的Sierra机器上。

所以:

 brew install pkg-config brew uninstall imagemagick brew install imagemagick@6 brew link imagemagick@6 --force 

成功:

 $ gem install rmagick Building native extensions. This could take a while... Successfully installed rmagick-2.16.0 Parsing documentation for rmagick-2.16.0 Installing ri documentation for rmagick-2.16.0 Done installing documentation for rmagick after 4 seconds 1 gem installed 

我的系统上出现了严重的错误,非常糟糕,以至于完全失败了,但是在安装完成之后,我终于可以安装RMagick for Ruby 1.8.7了

  • ImageMagick的老版本与自制软件
  • 一个新的1.8.7的Ruby版本
  • GCC的新版本

使用RVM rvm install 1.8.7安装新的Ruby版本也安装了一个新的GCC编译器:它删除了旧的GCC版本4.6并安装了GCC版本4.9。 显然GCC不能find正确的头,尽pipepkg-config。

在版本7.0.7-1你可以创build一个符号链接,但编译将失败后者。

 cd /usr/local/Cellar/imagemagick/7.0.7-1/include/ImageMagick-7 ln -s MagickWand/ wand ln -s MagicCore/ magick 

首先,如果安装了6.x,则不需要卸载imagemagick,如下所示。 你可以看到目前的“主”是7.0.7-8但是6.9.1-10仍然存在。

 $ brew info imagemagick imagemagick: stable 7.0.7-8 (bottled), HEAD Tools and libraries to manipulate images in many formats https://www.imagemagick.org/ /usr/local/Cellar/imagemagick/6.9.1-10 (1,450 files, 17.5MB) Poured from bottle on 2015-07-26 at 09:10:58 /usr/local/Cellar/imagemagick/7.0.6-9 (1,522 files, 22.8MB) Poured from bottle on 2017-08-21 at 14:44:16 From: https://github.com/Homebrew/homebrew-core/blob/master/Formula 

如果您没有旧的6.x版本,请安装imagemagick @ 6。

其次, 不要强制链接 imagemagick,特别是不要6. 编辑:见¹
除了–with-opt- *标志外,还需要设置PKG_CONFIG_PATH。

这对于我在High Sierra上适用于Ruby 1.9.3-p551上的brew设置:

 PKG_CONFIG_PATH=/usr/local/Cellar/imagemagick/6.9.1-10/lib/pkgconfig \ gem install rmagick -v '2.16.0' -- \ --with-opt-lib=/usr/local/Cellar/imagemagick/6.9.1-10/lib/ \ --with-opt-include=/usr/local/Cellar/imagemagick/6.9.1-10/include/ImageMagick-6/ 

构buildri文档失败,但这些都是无关紧要的。

¹:build筑工程,RMGICKsearchdylibpath虽然是错误的。 提出的问题#278澄清,如果这是可以解决的。 否则,需要libMagickWand等的手动符号链接。 可能仍然比手动链接特定的库更安全 – 然而,