Skip to content
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

Can't load ImageMagick API on Windows 8.1 #256

Closed
marekstodolny opened this issue Aug 5, 2015 · 5 comments
Closed

Can't load ImageMagick API on Windows 8.1 #256

marekstodolny opened this issue Aug 5, 2015 · 5 comments

Comments

@marekstodolny
Copy link

Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\wand\api.py", line 150, in <module>
    libraries = load_library()
  File "C:\Python34\lib\site-packages\wand\api.py", line 107, in load_library
    raise IOError('cannot find library; tried paths: ' + repr(tried_paths))
OSError: cannot find library; tried paths: ['C:\\Program Files\\ImageMagick-6.9.1-Q16\\CORE_RL_wand_.dll', 'C:\\Program Files\\ImageMagick-6.9.1-Q16\\CORE_RL_wand_HDRI.dll', 'C:\\Program Files\\ImageMagick-6.9.1-Q16\\CORE_RL_wand_-6.dll', 'C:\\Program Files\\ImageMagick-6.9.1-Q16\\CORE_RL_wand_-6HDRI.dll', 'C:\\Program Files\\ImageMagick-6.9.1-Q16\\CORE_RL_wand_-Q16.dll', 'C:\\Program Files\\ImageMagick-6.9.1-Q16\\CORE_RL_wand_-Q16HDRI.dll', 'C:\\Program Files\\ImageMagick-6.9.1-Q16\\CORE_RL_wand_-Q8.dll', 'C:\\Program Files\\ImageMagick-6.9.1-Q16\\CORE_RL_wand_-Q8HDRI.dll', 'C:\\Program Files\\ImageMagick-6.9.1-Q16\\CORE_RL_wand_-6.Q16.dll', 'C:\\Program Files\\ImageMagick-6.9.1-Q16\\CORE_RL_wand_-6.Q16HDRI.dll']

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:/processing/plyty/plyty.py", line 1, in <module>
    from wand.image import Image
  File "C:\Python34\lib\site-packages\wand\image.py", line 20, in <module>
    from .api import MagickPixelPacket, libc, libmagick, library
  File "C:\Python34\lib\site-packages\wand\api.py", line 176, in <module>
    'Try to install:\n  ' + msg)
ImportError: MagickWand shared library not found.
You probably had not installed ImageMagick library.
Try to install:
  http://docs.wand-py.org/en/latest/guide/install.html#install-imagemagick-on-windows

Process finished with exit code 1

Path is proper and libraries exist.

I tried to hardcode the paths and files in api.py, but had no success at all.

This is just plain weird.

@emcconville
Copy link
Owner

And both Python & ImageMagick are matching x86, or x86_64 architectures?

@marekstodolny
Copy link
Author

Yeah, they both match x86_64.
I'll check if x86 works.

Is it possible that this issue could be caused by NTFS filesystem permissions?

@marekstodolny
Copy link
Author

Well, it's not working.

ImageMagick 6.9.1 x86
Python 3.4.3 x86

@roelandschoukens
Copy link
Contributor

The issue is finding the required DLL libraries. In standard ImageMagick installations they are not in the PATH or MAGICK_HOME variable, but they're found in the paths listed in the windows registry under HKEY_LOCAL_MACHINE\SOFTWARE\ImageMagick\Current

Note that the coder and filter DLL modules are found in subdirectories of the installation.

I have patched api.py to find those paths on my system. I'm not sure how it works on other systems:

libwand = None
system = platform.system()
magick_home = os.environ.get('MAGICK_HOME')

# on Windows we're going to need to add some paths for the DLL loader
if system == 'Windows':
    dll_load_paths = []
    # read paths to coder and filter modules from registry if possible
    try:
        with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\ImageMagick\Current") as reg_key:
            libPath    = winreg.QueryValueEx(reg_key, "LibPath")
            coderPath  = winreg.QueryValueEx(reg_key, "CoderModulesPath")
            filterPath = winreg.QueryValueEx(reg_key, "FilterModulesPath")
            magick_home = libPath[0]
            dll_load_paths = [libPath[0], coderPath[0], filterPath[0]]
    except:
        # otherwise use MAGICK_HOME
        if magick_home:
            dll_load_paths = [magick_home]

    if dll_load_paths:
        os.environ['PATH'] = os.environ['PATH'] + ';' + ';'.join(dll_load_paths)

This of course requires importing winreg. I have inserted this in the find_library function, but I saw that was refactored since the last release.

@emcconville
Copy link
Owner

Closing this. Issues appears to be resolved in previous releases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants