Bundle无法在Mac OSX 10.7上安装RMagick gem。

24
我已经使用ImageMagick安装程序脚本https://github.com/maddox/magick-installer安装了ImageMagick。我正在使用RVM,Ruby 1.9.3p125,OSX Lion 10.7。问题似乎出现在MagickWand.h文件中,以下是完整日志。
/Users/pdjimeno/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb
checking for Ruby version >= 1.8.5... yes
extconf.rb:128: Use RbConfig instead of obsolete and deprecated Config.
checking for /usr/bin/gcc... yes
checking for Magick-config... yes
checking for ImageMagick version >= 6.4.9... yes
checking for HDRI disabled version of ImageMagick... yes
Package MagickCore was not found in the pkg-config search path.
Perhaps you should add the directory containing `MagickCore.pc'
to the PKG_CONFIG_PATH environment variable
No package 'MagickCore' found
Package MagickCore was not found in the pkg-config search path.
Perhaps you should add the directory containing `MagickCore.pc'
to the PKG_CONFIG_PATH environment variable
No package 'MagickCore' found
Package MagickCore was not found in the pkg-config search path.
Perhaps you should add the directory containing `MagickCore.pc'
to the PKG_CONFIG_PATH environment variable
No package 'MagickCore' found
Package MagickCore was not found in the pkg-config search path.
Perhaps you should add the directory containing `MagickCore.pc'
to the PKG_CONFIG_PATH environment variable
No package 'MagickCore' found
checking for stdint.h... yes
checking for sys/types.h... yes
checking for wand/MagickWand.h... no

Can't install RMagick 2.13.1. Can't find MagickWand.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
    --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=/Users/pdjimeno/.rvm/rubies/ruby-1.9.3-p125/bin/ruby

http://superuser.com/questions/400179/gcc-on-os-x-lion-with-xcode-4-3-1 - Niels Kristian
12个回答

46

修复此问题需要设置当前ImageMagick安装的include路径:

使用brew安装ImageMagick

brew install imagemagick

查找库

$ mdfind MagickWand.h
/usr/local/Cellar/imagemagick/6.7.5-7/include/ImageMagick/wand/MagickWand.h

安装rmagick gem

$ C_INCLUDE_PATH=/path gem install rmagick

例子:

$ C_INCLUDE_PATH=/usr/local/Cellar/imagemagick/6.7.5-7/include/ImageMagick/ gem install rmagick

一样。使用最后一个示例,以 ImageMagick/ 目录结尾。 - agmcleod
1
这行代码 C_INCLUDE_PATH=/usr/local/Cellar/imagemagick/6.7.5-7/include/ImageMagick/ gem install rmagick 让我成功安装了rmagick。这是最准确的答案。 - Francisco Quintero
2
无论如何,它都可以在任何一种情况下工作,但运行find /usr/local/Cellar -name MagickCore.pc并设置PKG_CONFIG_PATH环境变量对我很有帮助。 - acobster

27

如果您遇到了“找不到包xxx”的错误。

请查找该软件包并将其目录路径添加到PKG_CONFIG_PATH变量中,可在~/.bash_login~/.bash_profile文件中进行设置。

例如:

如果您遇到以下错误:

Package MagickCore was not found in the pkg-config search path.

找到文件所在位置:

$ mdfind magickcore.pc
/usr/local/homebrew/Cellar/imagemagick/6.7.7-6/lib/pkgconfig/MagickCore.pc

将以下代码添加到你的 bash_login 或 bash_profile 文件中:

export PKG_CONFIG_PATH="/opt/local/lib/pkgconfig:/usr/local/homebrew/Cellar/imagemagick/6.7.7-6/lib/pkgconfig/:$PKG_CONFIG_PATH"

记得执行 source 命令以加载 bash_login/profile 文件。


7
对我来说,唯一有效的方法是尝试了上述所有方法,但只有PKG_CONFIG_PATH=/usr/local/Cellar/imagemagick/6.7.7-6/lib/pkgconfig/ gem install rmagick才奏效。 - prikha
3
使用sudo C_INCLUDE_PATH=/usr/local/Cellar/imagemagick/6.7.7-6/include/ImageMagick/ PKG_CONFIG_PATH=/usr/local/Cellar/imagemagick/6.7.7-6/lib/pkgconfig/ gem install rmagick命令,我成功地安装了rmagick。然而,还存在其他问题,必须解除链接并重新安装imagemagick才能解决。虽然Ruby比Node.js等其他语言更成熟,但在不同版本的Ruby和Gems之间切换仍然不太容易。 - james_womack
这个对我有用。我使用Mountain Lion和homebrew + rbenv。 - yagooar
C_INCLUDE_PATH 没有起作用,但这个方法很有帮助,谢谢! - Ivan Linko

24

我建议您使用brew来管理二进制依赖项。您可以通过brew轻松安装imageMagick,像这样:

brew install imagemagick

这是我系统上的内容:

imagemagick 6.7.1-1
http://www.imagemagick.org
Depends on: jpeg, libtiff, little-cms, jasper
/usr/local/Cellar/imagemagick/6.7.1-1 (1389 files, 32M)
http://github.com/mxcl/homebrew/commits/master/Library/Formula/imagemagick.rb

我的机器和ruby版本与你相同。


Imagemagick已经安装好了,我认为那不是问题所在。 - PabloJimeno
1
我觉得问题确实出在安装上。可能是一些头文件没有放在预期的位置,或者根本就缺失了。我猜只需要简单地卸载imagemagick,然后用brew重新安装会比调试这个相当复杂的堆栈跟踪要容易得多。但随你便 =) - Ekampp

20

目前,通过brew install imagemagick安装的默认版本为imagemagick 7,但与rmagick不兼容。解决方法如下:

  1. 使用Homebrew卸载当前已安装的imagemagick版本

brew uninstall imagemagick

  1. 安装imagemagick 6:

brew install imagemagick@6

  1. 使用pkgconfig变量运行gem install(根据你的配置可能需要sudo

PKG_CONFIG_PATH=/usr/local/opt/imagemagick@6/lib/pkgconfig gem install rmagick


16

我也找到了使用Homebrew的解决方案:

brew remove --force pkg-config
brew install pkg-config

然后

gem install rmagick

8

1)通过安装程序进行安装

http://cactuslab.com/imagemagick/

2)尝试使用gem install rmagick命令进行安装

如果出现checking for wand/MagickWand.h... no错误,请执行以下操作:

mdfind MagickWand.h

寻找类似的东西

/Users/user/ImageMagick-6.8.3/include/ImageMagick-6/wand/MagickWand.h

在终端中输入

C_INCLUDE_PATH=/Users/user/ImageMagick-6.8.3/include/ImageMagick-6/ gem install rmagick

如果你遇到了这个错误(因为我曾经遇到过):“在pkg-config搜索路径中未找到MagickCore软件包。”
请执行以下操作:
mdfind MagickCore.pc

找到类似于 /opt/ImageMagick/lib/pkgconfig/MagickCore.pc 的东西

最后在终端中键入:

PKG_CONFIG_PATH=/opt/ImageMagick/lib/pkgconfig/ gem install rmagick

谢谢,这个解决方案在我的Mac上有效。PKG_CONFIG_PATH=/opt/ImageMagick/lib/pkgconfig/ gem install rmagick - Ahmad Hussain

5
安德烈·亚西尼辛的解决方案适用于我:

mdfind MagickCore.pc

找到类似于 /opt/ImageMagick/lib/pkgconfig/MagickCore.pc 的东西

最后在终端中输入:

PKG_CONFIG_PATH=/opt/ImageMagick/lib/pkgconfig/ gem install rmagick

3
我尝试了很多方法,但最终的解决方案是: brew uninstall --force imagemagick # 卸载所有版本
然后 brew install imagemagick@6 最后 gem install rmagick

3

当我遇到这个问题时,它报错说找不到MagickCore.pc文件,所以我进行了以下操作;

$ mdfind MagickCore.h
/usr/local/Cellar/imagemagick/6.8.0-10/include/ImageMagick/magick/MagickCore.h
/usr/local/Cellar/imagemagick/6.7.7-6/include/ImageMagick/magick/MagickCore.h

$ export PKG_CONFIG_PATH=/usr/local/Cellar/imagemagick/6.8.0-10/lib/pkgconfig/
$ gem install rmagick

并且它运作良好!


2

对于El Capitan用户,

需要包含PKG_CONFIG_FILE和C_INCLUDE_PATH两个变量。我成功运行的命令是:

sudo C_INCLUDE_PATH=/usr/local/Cellar/imagemagick/6.9.2-4/include/ImageMagick/ PKG_CONFIG_PATH=/usr/local/Cellar/imagemagick/6.9.2-4/lib/pkgconfig/ gem install rmagick


1
"6.9.2-4" 文件夹的更改取决于安装的 ImageMagic 版本。否则,它可以完美运行。 - drKreso

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接