New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MagickWand shared library not found #141

Closed
hit9 opened this Issue Aug 22, 2013 · 37 comments

Comments

@hit9

hit9 commented Aug 22, 2013

Exception information:

Traceback (most recent call last):
  File "testss.py", line 1, in <module>
    from wand.image import Image
  File "/Users/hit9/spam/testfirfffff/venv/lib/python2.7/site-packages/wand/image.py", line 20, in <module>
    from .api import MagickPixelPacket, libc, libmagick, library
  File "/Users/hit9/spam/testfirfffff/venv/lib/python2.7/site-packages/wand/api.py", line 156, in <module>
    'Try to install:\n  ' + msg)
ImportError: MagickWand shared library not found.
You probably had not installed ImageMagick library.
Try to install:
  brew install imagemagick

I am using OSX10.8

And I installed imagemagick via brew:

$ brew install imagemagick
Warning: imagemagick-6.8.6-3 already installed

And here is my result run ls in /usr/local/lib :

$ ls -l  /usr/local/lib/ | grep libMagick
lrwxr-xr-x   1 hit9  admin       59 Aug 22 11:04 libMagick++-6.Q16.1.dylib -> ../Cellar/imagemagick/6.8.6-3/lib/libMagick++-6.Q16.1.dylib
lrwxr-xr-x   1 hit9  admin       57 Aug 22 11:04 libMagick++-6.Q16.dylib -> ../Cellar/imagemagick/6.8.6-3/lib/libMagick++-6.Q16.dylib
lrwxr-xr-x   1 hit9  admin       54 Aug 22 11:04 libMagick++-6.Q16.la -> ../Cellar/imagemagick/6.8.6-3/lib/libMagick++-6.Q16.la
lrwxr-xr-x   1 hit9  admin       61 Aug 22 11:04 libMagickCore-6.Q16.1.dylib -> ../Cellar/imagemagick/6.8.6-3/lib/libMagickCore-6.Q16.1.dylib
lrwxr-xr-x   1 hit9  admin       59 Aug 22 11:04 libMagickCore-6.Q16.dylib -> ../Cellar/imagemagick/6.8.6-3/lib/libMagickCore-6.Q16.dylib
lrwxr-xr-x   1 hit9  admin       56 Aug 22 11:04 libMagickCore-6.Q16.la -> ../Cellar/imagemagick/6.8.6-3/lib/libMagickCore-6.Q16.la
lrwxr-xr-x   1 hit9  admin       61 Aug 22 11:04 libMagickWand-6.Q16.1.dylib -> ../Cellar/imagemagick/6.8.6-3/lib/libMagickWand-6.Q16.1.dylib
lrwxr-xr-x   1 hit9  admin       59 Aug 22 11:04 libMagickWand-6.Q16.dylib -> ../Cellar/imagemagick/6.8.6-3/lib/libMagickWand-6.Q16.dylib
lrwxr-xr-x   1 hit9  admin       56 Aug 22 11:04 libMagickWand-6.Q16.la -> ../Cellar/imagemagick/6.8.6-3/lib/libMagickWand-6.Q16.la
lrwxr-xr-x   1 hit9  admin       42 Aug 22 11:42 libMagickWand.dylib -> /usr/local/lib/libMagickWand-6.Q16.1.dylib

I noticed there was a few issues similar to this. But I tried the solutions, and issue still exists. Hope your solution, thanks.

@dahlia

This comment has been minimized.

Collaborator

dahlia commented Aug 22, 2013

It seems your Python doesn’t find shared libraries at /usr/local/lib/ by default. How does your ctypes.util.find_library() work?

>>> ctypes.util.find_library('png')
'/usr/local/lib/libpng.dylib'
>>> ctypes.util.find_library('MagickWand-Q16')
'/usr/local/lib/libMagickWand-Q16.dylib'
@hit9

This comment has been minimized.

hit9 commented Aug 22, 2013

I have tested this :

>>> import ctypes.util
>>> ctypes.util.find_library('MagickWand-Q16')
>>> print ctypes.util.find_library('MagickWand-Q16')                                                                                                                         None
>>> print ctypes.util.find_library('MagickWand-6.Q16')
/usr/local/lib/libMagickWand-6.Q16.dylib
>>> ctypes.util.find_library('png')
'/usr/local/lib/libpng.dylib'

Thanks for your reply! 😄

@dahlia

This comment has been minimized.

Collaborator

dahlia commented Aug 22, 2013

How about ctypes.util.find_library('MagickWand')?

@hit9

This comment has been minimized.

hit9 commented Aug 22, 2013

this got None

>>> print ctypes.util.find_library('MagickWand')
None
@dahlia

This comment has been minimized.

Collaborator

dahlia commented Aug 22, 2013

That’s strange. You have /usr/local/lib/libMagickWand.dylib, right? It shouldn’t return None. Anyway I will add suffix '-6.Q16' as well.

@dahlia

This comment has been minimized.

Collaborator

dahlia commented Aug 22, 2013

Wait, it’s already included. Which Wand version do you use?

@hit9

This comment has been minimized.

hit9 commented Aug 22, 2013

No, I dont have libMagickWand.dylib,

testwand ❯ ls -l /usr/local/lib/ | grep libMagickWand     
lrwxr-xr-x   1 hit9  admin       61 Aug 22 13:33 libMagickWand-6.Q16.1.dylib -> ../Cellar/imagemagick/6.8.6-3/lib/libMagickWand-6.Q16.1.dylib
lrwxr-xr-x   1 hit9  admin       59 Aug 22 13:33 libMagickWand-6.Q16.dylib -> ../Cellar/imagemagick/6.8.6-3/lib/libMagickWand-6.Q16.dylib
lrwxr-xr-x   1 hit9  admin       56 Aug 22 13:33 libMagickWand-6.Q16.la -> ../Cellar/imagemagick/6.8.6-3/lib/libMagickWand-6.Q16.la

I use 0.3.3:

testwand ❯ pip show wand
---
Name: Wand
Version: 0.3.3
Location: /usr/local/lib/python2.7/site-packages
Requires: 
@hit9

This comment has been minimized.

hit9 commented Aug 22, 2013

I have seen the source code, suffix '-6.Q16' already there.

@dahlia

This comment has been minimized.

Collaborator

dahlia commented Aug 22, 2013

One possible workaround would be to set MAGICK_HOME=/usr/local environment variable, but I’d like to fix it to get it right.

@hit9

This comment has been minimized.

hit9 commented Aug 22, 2013

thx. I tried and it , but .

testwand ❯ MAGICK_HOME=/usr/local                                                                                                                                         
testwand ❯ echo $MAGICK_HOME     
/usr/local
testwand ❯ python testss.py      
Traceback (most recent call last):
  File "testss.py", line 1, in <module>
    from wand.image import Image
  File "/usr/local/lib/python2.7/site-packages/wand/image.py", line 20, in <module>
    from .api import MagickPixelPacket, libc, libmagick, library
  File "/usr/local/lib/python2.7/site-packages/wand/api.py", line 156, in <module>
    'Try to install:\n  ' + msg)
ImportError: MagickWand shared library not found.
You probably had not installed ImageMagick library.
Try to install:
  brew install imagemagick
@dahlia

This comment has been minimized.

Collaborator

dahlia commented Aug 22, 2013

@hit9 How does it print?:

try:
    import wand.api
except ImportError:
    pass
import sys
sys.modules['wand._api'].load_libraries()

It would raise an IOError, but I wonder its error message (which would contain tried paths).

@hit9

This comment has been minimized.

hit9 commented Aug 23, 2013

it raised AttributeError:

Traceback (most recent call last):
  File "ye.py", line 6, in <module>
    sys.modules['wand._api'].load_libraries()
AttributeError: 'module' object has no attribute 'load_libraries'
@dahlia

This comment has been minimized.

Collaborator

dahlia commented Aug 23, 2013

@hit9 I am sorry, there was a typo: not load_libraries() but load_library(). 😭

@dahlia

This comment has been minimized.

Collaborator

dahlia commented Aug 23, 2013

Or we can try this patch as well to print tried paths:

diff --git a/wand/api.py b/wand/api.py
index aef6563..12e536e 100644
--- a/wand/api.py
+++ b/wand/api.py
@@ -131,6 +131,7 @@ sys.modules['wand._api'] = sys.modules['wand.api']
 try:
     libraries = load_library()
 except (OSError, IOError):
+    raise
     msg = 'http://docs.wand-py.org/en/latest/guide/install.html'
     if sys.platform.startswith('freebsd'):
         msg = 'pkg_add -r'
@hit9

This comment has been minimized.

hit9 commented Aug 23, 2013

oh.. And the new exception is :

Traceback (most recent call last):
  File "ye.py", line 6, in <module>
    sys.modules['wand._api'].load_library()
  File "/usr/local/lib/python2.7/site-packages/wand/api.py", line 102, in load_library
    raise IOError('cannot find library; tried paths: ' + repr(tried_paths))
IOError: cannot find library; tried paths: ['/usr/local/lib/libMagickWand-6.Q16.dylib']
@dahlia

This comment has been minimized.

Collaborator

dahlia commented Aug 23, 2013

However you have /usr/local/lib/libMagickWand-6.Q16.dylib, right?

@hit9

This comment has been minimized.

hit9 commented Aug 23, 2013

Yes, I have it. I doubt that error occurred in load_library(), the later process

@hellothisistim

This comment has been minimized.

hellothisistim commented Sep 21, 2013

I'm seeing the same issue on OSX 10.8.4 with Wand 0.3.5. I also installed ImageMagick 6.8.6-3 via Homebrew.

Have there been any updates on the issue?

@dahlia

This comment has been minimized.

Collaborator

dahlia commented Sep 22, 2013

Sorry, we currently cannot reproduce this.

@hellothisistim

This comment has been minimized.

hellothisistim commented Oct 3, 2013

I solved my problem by uninstalling my old Python 2.7 from python.org and built a fresh one using homebrew. Problem solved.

Thanks for making (and sharing) Wand!

@pabluch

This comment has been minimized.

pabluch commented Jan 6, 2014

I don't know how it is on mac but I had this issue on Windows and spent 1.5 hour just to discover that I overlooked a trivial thing... I had 32 bit python installed and 64bit imageMagick ... no wonder ctypes could not load imagemagick's libraries - hope it helps somebody
.

@robertfigiel

This comment has been minimized.

robertfigiel commented Jan 9, 2014

Hey pabluch, had exactly the same Windows problem and re-installing the 32-bit version helped. Thanks!

@dahlia

This comment has been minimized.

Collaborator

dahlia commented May 1, 2014

@hit9, I wonder whether you solved this or it’s still unsolved. A friend of mine faced the exactly same problem to you, so I look into this problem, and then finally got the following:

>>> import ctypes
>>> ctypes.CDLL('/usr/local/lib/libMagickWand-6.Q16.dylib')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/usr/local/lib/libMagickWand-6.Q16.dylib, 6): Library not loaded: /usr/local/lib/libfreetype.6.dylib
Referenced from: /usr/local/lib/libMagickWand-6.Q16.dylib
Reason: image not found

So we tried installing freetype, and then it worked perfectly.

@dahlia

This comment has been minimized.

Collaborator

dahlia commented May 1, 2014

So we tried installing freetype, and then it worked perfectly.

Oh more exactly, it still was installed using Homebrew, but not correctly linked.

@hit9

This comment has been minimized.

hit9 commented May 1, 2014

I‘m sorry, but I almost forget what this issue really is..

@midtskogen

This comment has been minimized.

midtskogen commented Jun 16, 2015

I'm also getting "ImportError: MagickWand shared library not found", but I have it installed in /usr/lib/x86_64-linux-gnu/ (Ubuntu 14.04). Actually, everything works fine if I run the Python program causing the error from the command line, but if it's called from a C program using execvp(), I get this error.

Any suggestions how to fix it or how to debug it?

@pabluch

This comment has been minimized.

pabluch commented Jun 16, 2015

Maybe check if the same python is run via execvp as from command line,
and I don't remember how it is with environment variables and execvp
in your case.

On 16 June 2015 at 09:17, midtskogen notifications@github.com wrote:

I'm also getting "ImportError: MagickWand shared library not found", but I
have it installed in /usr/lib/x86_64-linux-gnu/ (Ubuntu 14.04). Actually,
everything works fine if I run the Python program causing the error from
the command line, but if it's called from a C program using execvp(), I get
this error.

Any suggestions how to fix it or how to debug it?


Reply to this email directly or view it on GitHub
#141 (comment).


Pawel Lukaszewicz
+48 889 252 219

@midtskogen

This comment has been minimized.

midtskogen commented Jun 17, 2015

The problem seems to be that find_library in api.py gets an IOError(10, 'No child processes') (upon calling platform.system(), but ignoring that the same exception gets raised when calling ctypes.util.find_library later). I don't know why. This only happens when the Python program gets called from a C program using execvp().

I think the problem is with the platform module, not Wand. The following program runs fine from the command line:

#!/usr/bin/env python2
import platform
print(platform.system())

But when run from a C program using I get:

Traceback (most recent call last):
  File "/home/steinar/test.py", line 3, in <module>
    print platform.system()
  File "/usr/lib/python2.7/platform.py", line 1333, in system
    return uname()[0]
  File "/usr/lib/python2.7/platform.py", line 1300, in uname
    processor = _syscmd_uname('-p','')
  File "/usr/lib/python2.7/platform.py", line 1035, in _syscmd_uname
    rc = f.close()

A minimal C program:

#include <unistd.h>
#include <signal.h>

int main(int argc, char **argv)
{
  char *args[] = { "/home/steinar/test.py", 0 };

  signal(SIGCHLD, SIG_IGN);
  if (!fork())
    execvp("/home/steinar/test.py", args);
  return 0;
}

It works in python3. It also works if I remove the signal(SIGCHLD, SIG_IGN) line.

@sp-ivan-ortega

This comment has been minimized.

sp-ivan-ortega commented Jan 19, 2017

I have found a solution.
The problem is:
Wand try to find a file like that: libMagickWand.dylib in /usr/local/lib/
But if you install ImageMagick with Homebrew, the file generated is libMagickWand-6.Q16.dylib
And Wand never find it.
So, you have 2 solutions:

  1. Create a symbol link from libMagickWand-6.Q16.dylib to libMagickWand.dylib
  2. You can install by MacPorts or from binaries testing that they create the file.

I have installed the ImageMagick for The Capitan from:
http://cactuslab.com/assets/installers/ImageMagick-6.9.1-0.pkg.zip
and I declare:
export MAGICK_HOME=/opt/ImageMagick

@blaflamme

This comment has been minimized.

blaflamme commented Jan 24, 2017

With brew you can:

  • $ brew install imagemagick@6
  • $ export MAGICK_HOME=/usr/local/opt/imagemagick@6
@TheMengzor

This comment has been minimized.

TheMengzor commented Jan 26, 2017

Yesterday I made brew update && brew upgrade and got the same error.
Of course, you can do one of two previous comments, but they are require you to install additional software, so you could check 6.x version in your /usr/local/Cellar/imagemagick/:

ls -1 /usr/local/Cellar/imagemagick/

In my case I had:

6.9.3-6
6.9.6-0
7.0.4-5

And if you have any 6.x, just run:

export MAGICK_HOME=/usr/local/Cellar/imagemagick/6.9.6-0

Of course replace 6.9.6-0 with your version 😆

@dbader

This comment has been minimized.

dbader commented Jan 30, 2017

Got the same error after a brew upgrade (which installed libImageMagick 7.x). I'm only using imagemagick for Wand, so I was able to fix the issue by telling brew to use ImageMagick 6.x:

brew link imagemagick@6 --force
@DaniZz

This comment has been minimized.

DaniZz commented Apr 6, 2017

python for Mac (El Capitan) is a joke. And a bad one.
Imagick does not work.
Pygame does not work anymore.

@mugbya

This comment has been minimized.

mugbya commented Apr 27, 2017

brew unlink imagemagick

brew link imagemagick@6 --force

@dbader ths

@alonsopg

This comment has been minimized.

alonsopg commented Apr 28, 2017

Same issue here.. @mugbya I got:


user@MacBook-Pro-de-User-3:~$ brew link imagemagick@6 --force
Error: No such keg: /usr/local/Cellar/imagemagick@6
@TheMengzor

This comment has been minimized.

TheMengzor commented Apr 28, 2017

@alonsopg $ brew install imagemagick@6 first

@ntarocco

This comment has been minimized.

ntarocco commented Aug 14, 2017

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

plus adding to the PATH works for me

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