2

Update

Perhaps this is the cause?

>>> from ctypes import *
>>> cdll.LoadLibrary('libMagickWand-6.Q16.so.2')
...
OSError: /home/myuname/anaconda3/bin/../lib/libgomp.so.1: version `GOMP_4.0' not found (required by /usr/lib/x86_64-linux-gnu/libMagickWand-6.Q16.so.2)

Unclear how to fix though.


Using the python wand package. Followed installation instructions by running:

sudo apt install libmagickwand-dev imagemagick
pip install wand

But I get the following error when trying to import Image:

>>> from wand.image import Image
...
    raise IOError('cannot find library; tried paths: ' + repr(tried_paths))
OSError: cannot find library; tried paths: ['libMagickWand-6.Q16.so.2', 'libMagickWand-6.Q16.so.2']

During handling of the above exception, another exception occurred:
...
ImportError: MagickWand shared library not found.
You probably had not installed ImageMagick library.
Try to install:
  apt-get install libmagickwand-dev

Not sure what's going on. Running ldconfig -p | grep -i wand gives me:

libMagickWand-6.Q16.so.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libMagickWand-6.Q16.so.2
libMagickWand-6.Q16.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libMagickWand-6.Q16.so

Also running ctypes shows the library:

>>> from ctypes.util import find_library
>>> find_library('MagickWand')
'libMagickWand-6.Q16.so.2'

Confirm that it's not v7:

$ convert -version
Version: ImageMagick 6.8.9-9 Q16 x86_64 2017-05-26 http://www.imagemagick.org

1 Answers1

2

Install wand in Ubuntu 16.04 from the default Ubuntu repositories.

sudo apt install python-wand libmagickwand-dev 

Create an image called mona-lisa.png in your own home directory to use in the following example code from the wand documentation.

from wand.image import Image
from wand.display import display

with Image(filename='mona-lisa.png') as img:
    print(img.size)
    for r in 1, 2, 3:
        with img.clone() as i:
            i.resize(int(i.width * r * 0.25), int(i.height * r * 0.25))
            i.rotate(90 * r)
            i.save(filename='mona-lisa-{0}.png'.format(r))
            display(i)

If you are running this code from the terminal, press Enter twice after the end of the code to run the code. This code should run successfully and open the image in a separate window and show the console output. Close all the image windows that the Python code opened by clicking on the X before exiting from the Python interpreter.

I tried troubleshooting your output and got these results:

>>> from ctypes import *
>>> cdll.LoadLibrary('libMagickWand-6.Q16.so.2')
<CDLL 'libMagickWand-6.Q16.so.2', handle 266d6a0 at 7fb271c966d0>

There were no errors on my computer, however I discovered what caused this error on your computer:

OSError: /home/myuname/anaconda3/bin/../lib/libgomp.so.1: version `GOMP_4.0' not found (required by /usr/lib/x86_64-linux-gnu/libMagickWand-6.Q16.so.2)

Clearly the error on your computer is caused by anaconda. Anaconda is known for making a big mess out of the default paths for many Python modules. To fix it you need to tell conda the paths to Python files that were installed by apt.

You can use symbolic links to tell conda the paths to Python files that were installed by apt. Put the symbolic links in conda's own lib/python/site-packages directory which for you would be something like: /home/ksindi/anaconda3/lib/python/site-packages if ksindi is your username.

No sir, I do not like anaconda for making me do all this extra work to make conda recognize the Python packages that I installed with apt.

karel
  • 114,770
  • thanks for confirming it works for you on 16.04 Unfortunately I can't import Image still and get the same error even after installing python-wand. I've updated my question as I might have found the underlying issue. Still don't know how to fix though. – Kamil Sindi Jul 16 '17 at 18:52
  • I hope I got the path right. As you can see from reading my answer, I don't have anaconda installed. If there isn't something like /home/ksindi/anaconda3/lib/python/site-packages then maybe conda is using a different version of Python like /home/ksindi/anaconda3/lib/python3.5/site-packages – karel Jul 16 '17 at 19:14
  • you're absolutely right. anaconda was the issue. funny enough i was just about to try that when i got home. – Kamil Sindi Jul 16 '17 at 19:27
  • 1
    @ksindi I didn't say everything about Anaconda that I wanted to say in my answer because it is perhaps not entirely relevant but consider this example. On Stack Overflow there are 8 questions about glueviz and 7 of them are also about Anaconda. This is a Windows/Mac way of thinking about Anaconda, but it is not the Ubuntu way. I have glueviz (linked data visualization) from the default Ubuntu 16.04 repos installed, but I do not have Anaconda installed on my computer. – karel Jul 18 '17 at 14:37