Skip to content

Instantly share code, notes, and snippets.

@dongyuwei
Last active July 25, 2024 19:44
Show Gist options
  • Save dongyuwei/3668fcc69f557dd32c46 to your computer and use it in GitHub Desktop.
Save dongyuwei/3668fcc69f557dd32c46 to your computer and use it in GitHub Desktop.
ImportError: MagickWand shared library not found. You probably had not installed ImageMagick library.

Wand==0.3.7, Python 3.4.3, OSX EI Capitan 10.11

when run from wand.image import Image it throw errors:

ImportError: MagickWand shared library not found. You probably had not installed ImageMagick library. Try to install: brew install freetype imagemagick

ok, first I try this:

brew install freetype imagemagick, but

Warning: freetype-2.6_1 already installed Warning: imagemagick-6.9.2-4 already installed

what's the fuck?

run convert -h

dyld: Library not loaded: /usr/local/lib/libfreetype.6.dylib Referenced from: /usr/local/bin/convert Reason: Incompatible library version: convert requires version 19.0.0 or later, but libfreetype.6.dylib provides version 16.0.0 Trace/BPT trap: 5

Ok, Incompatible library version, I got you!

So here is the final solutions for me.

  1. brew uninstall freetype imagemagick
  2. brew install freetype
  3. brew link --overwrite freetype
  4. brew install imagemagick
@shaleh
Copy link

shaleh commented Mar 19, 2018

On High Sierra I did this:

$ brew install imagemagick@6
$ export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/opt/imagemagick@6/lib/
$ python -c "from wand.image import Image"  # If this works all is well. Failure is noisy

No need to uninstall imagemagick 7. However, you do need to set the variable somewhere like ~/.bash_profile or in your service's startup script.

Just imagemagick@7 does not work, even with the variable set to point to it. At least for me.

@vishul
Copy link

vishul commented Oct 11, 2018

@shaleh This works! I had imagemagick@6 installed but apparently the libPath was not set correctly. Thanks 👍 :)

@juliansrepository
Copy link

If anyone is still suffering, this worked for me:

export MAGICK_HOME=/opt/homebrew/opt/imagemagick

@vishk23
Copy link

vishk23 commented Mar 6, 2023

@juliansrepository THANKS !! only thing that worked

@Danzil21
Copy link

@juliansrepository thanks a lot, I spent a lot of time solving the problem, but everything turned out to be much easier)

@iqfareez
Copy link

If anyone is still suffering, this worked for me:

export MAGICK_HOME=/opt/homebrew/opt/imagemagick

Working for me. Thanks 👍

@vishnupriyavr
Copy link

If anyone is still suffering, this worked for me:

export MAGICK_HOME=/opt/homebrew/opt/imagemagick

Thanks, this works

@pythoninthegrass
Copy link

This was close. What worked for me was:

# install imagemagick v6
brew uninstall imagemagick
brew install imagemagick@6
brew unlink imagemagick
brew link imagemagick@6 --force

# ~/.bashrc
export BREW_PREFIX=$(brew --prefix)
export MAGICK_HOME="$BREW_PREFIX/opt/imagemagick@6"

now able to import pdftotree as expected on an M1 Pro.

@happybub
Copy link

If setting export MAGICK_HOME=/opt/homebrew/opt/imagemagick didn't work, then re-open your terminal, run echo $MAGICK_HOME. If nothing shows up, here is what you can do:

  1. Make it permanent
    • Open your shell profile .bash_profile (or .zshrc).
    • Add this line: export MAGICK_HOME=/opt/homebrew/opt/imagemagick.
    • Save and exit, then type source ~/.bash_profile (or .zshrc) to apply changes.
  2. Quick Python fix
    If you need a quick fix in Python instead of permanently change your system variables, use this snippet:
    import os
    if not os.environ.get('MAGICK_HOME'):
        print("Setting MAGICK_HOME temporarily")
        os.environ['MAGICK_HOME'] = '/opt/homebrew/opt/imagemagick' # or imagemagick@6, imagemagick@7 whatever installed there

This Python code only sets MAGICK_HOME temporarily during the script runtime. For a permanent fix, update your shell profile as described above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment