解决brew默认安装iamgemagick7导致wand库运行错误问题

写在前面

因为前几天手贱,升级了一下homebrew下的formula,不小心把imagemagick升级到了7的版本,在运行项目的时候一直报错brew install freetype imagemagick,找了很久才发现在wand库下的api.py文件中versions = '', '-6', '-Q16', '-Q8', '-6.Q16'以及options = '', 'HDRI', 'HDRI-2',推测原因是因为索引不到/usr/local/lib中imagemagick7的相关库,尝试改了几次源码都没有解决问题,其实python的Wand库最新还是0.4.4的版本,并不支持imagemagick7,,最后想办法把imagemagick降到6的版本。
但是homebrew安装指定版本又是一个大问题,查找的brew versions命令已经被移除了。后来在stackoverflow上找到了一篇有用的回答,才最终解决问题。https://stackoverflow.com/que...

Homebrew

homebrew把自己的formula都放在/usr/local/Cella/下的文件中.

卸载imagemagick7的版本

imagemagick7在/usr/local/Cella/下的名称为imagemagick,imagemagick6的名称为imagemagick@6,使用brew uninstall imagemagick会卸载imagemagick7.如果没有安装过imagemagick的话,可以忽略这一步。

查找imagemagick

输入brew search imagemagick会出现如下的显示,画勾的是已经安装的版本。

FlyingpangdeMacBook-Pro:~ Flyingpang$ brew search imagemagick
==> Searching local taps...
imagemagick@6 ✔                          imagemagick
==> Searching taps on GitHub...
==> Searching blacklisted, migrated and deleted formulae...

如果没有安装imagemagick6的话,使用 brew install imagemagick@6来安装。

做符号链接

安装完以后,它会有如下的提示文字。

This formula is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/imagemagick@6/bin:$PATH"' >> ~/.bash_profile

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/imagemagick@6/lib
    CPPFLAGS: -I/usr/local/opt/imagemagick@6/include
For pkg-config to find this software you may need to set:
    PKG_CONFIG_PATH: /usr/local/opt/imagemagick@6/lib/pkgconfig
    

如果安装的是最新的版本,brew会自动给你做好符号链接。由于这个是旧版的,所以没有做链接。先按照提示运行echo 'export PATH="/usr/local/opt/imagemagick@6/bin:$PATH"' >> ~/.bash_profile,运行完之后记得使用命令source ~/.bash_profile让修改生效。
然后cd /usr/local/lib,该目录下都是一些常用的库,你需要把刚装好的imagemagick@6下的所有lib移动到这边,lib的路径/usr/local/Cellar/imagemagick@6/6.9.9-23/lib,注意,其中的6.9.9-23根据你安装的版本改变。

FlyingpangdeMacBook-Pro:lib Flyingpang$ ln -s /usr/local/Cellar/imagemagick@6/6.9.9-23/lib/libMagickCore-6.Q16.dylib libMagickCore-6.Q16.dylib
FlyingpangdeMacBook-Pro:lib Flyingpang$ ln -s /usr/local/Cellar/imagemagick@6/6.9.9-23/lib/libMagick++-6.Q16.8.dylib libMagick++-6.Q16.8.dylib
FlyingpangdeMacBook-Pro:lib Flyingpang$ ln -s /usr/local/Cellar/imagemagick@6/6.9.9-23/lib/libMagickCore-6.Q16.la libMagickCore-6.Q16.la
FlyingpangdeMacBook-Pro:lib Flyingpang$ ln -s /usr/local/Cellar/imagemagick@6/6.9.9-23/lib/libMagick++-6.Q16.a libMagick++-6.Q16.a
FlyingpangdeMacBook-Pro:lib Flyingpang$ ln -s /usr/local/Cellar/imagemagick@6/6.9.9-23/lib/libMagickWand-6.Q16.5.dylib libMagickWand-6.Q16.5.dylib
FlyingpangdeMacBook-Pro:lib Flyingpang$ ln -s /usr/local/Cellar/imagemagick@6/6.9.9-23/lib/libMagick++-6.Q16.dylib libMagick++-6.Q16.dylib
FlyingpangdeMacBook-Pro:lib Flyingpang$ ln -s /usr/local/Cellar/imagemagick@6/6.9.9-23/lib/libMagickWand-6.Q16.a libMagickWand-6.Q16.a
FlyingpangdeMacBook-Pro:lib Flyingpang$ ln -s /usr/local/Cellar/imagemagick@6/6.9.9-23/lib/libMagick++-6.Q16.la libMagick++-6.Q16.la
FlyingpangdeMacBook-Pro:lib Flyingpang$ ln -s /usr/local/Cellar/imagemagick@6/6.9.9-23/lib/libMagickWand-6.Q16.dylib libMagickWand-6.Q16.dylib
FlyingpangdeMacBook-Pro:lib Flyingpang$ ln -s /usr/local/Cellar/imagemagick@6/6.9.9-23/lib/libMagickCore-6.Q16.5.dylib libMagickCore-6.Q16.5.dylib
FlyingpangdeMacBook-Pro:lib Flyingpang$ ln -s /usr/local/Cellar/imagemagick@6/6.9.9-23/lib/libMagickWand-6.Q16.la libMagickWand-6.Q16.la
FlyingpangdeMacBook-Pro:lib Flyingpang$ ln -s /usr/local/Cellar/imagemagick@6/6.9.9-23/lib/libMagickCore-6.Q16.a libMagickCore-6.Q16.a
FlyingpangdeMacBook-Pro:lib Flyingpang$ ln -s /usr/local/Cellar/imagemagick@6/6.9.9-23/lib/ImageMagick ImageMagick

现在wand库就可以直接用了。

你可能感兴趣的:(imagemagick,homebrew)