解決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...python

Homebrew

homebrew把本身的formula都放在/usr/local/Cella/下的文件中.api

卸載imagemagick7的版本

imagemagick7在/usr/local/Cella/下的名稱爲imagemagick,imagemagick6的名稱爲imagemagick@6,使用brew uninstall imagemagick會卸載imagemagick7.若是沒有安裝過imagemagick的話,能夠忽略這一步。bash

查找imagemagick

輸入brew search imagemagick會出現以下的顯示,畫勾的是已經安裝的版本。this

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來安裝。code

作符號連接

安裝完之後,它會有以下的提示文字。orm

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庫就能夠直接用了。homebrew

相關文章
相關標籤/搜索