Page 1 of 1

Python can't register CORE_RL_wand_.dll

Posted: 2015-09-15T18:55:15-07:00
by roelandsch
I tried to use Wand via Python and it fails to load the module:

Code: Select all

Traceback (most recent call last):
  File "C:\Program Files\Python 3.5\lib\site-packages\wand\api.py", line 150, in <module>
    libraries = load_library()
  File "C:\Program Files\Python 3.5\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.2-Q16-HDRI\\CORE_RL_wand_.dll', 'C:\\Program Files\\ImageMagick-6.9.2-Q16-HDRI\\CORE_RL_wand_HDRI.dll', 'C:\\Program Files\\ImageMagick-6.9.2-Q16-HDRI\\CORE_RL_wand_-6.dll', 'C:\\Program Files\\ImageMagick-6.9.2-Q16-HDRI\\CORE_RL_wand_-6HDRI.dll', 'C:\\Program Files\\ImageMagick-6.9.2-Q16-HDRI\\CORE_RL_wand_-Q16.dll', 'C:\\Program Files\\ImageMagick-6.9.2-Q16-HDRI\\CORE_RL_wand_-Q16HDRI.dll', 'C:\\Program Files\\ImageMagick-6.9.2-Q16-HDRI\\CORE_RL_wand_-Q8.dll', 'C:\\Program Files\\ImageMagick-6.9.2-Q16-HDRI\\CORE_RL_wand_-Q8HDRI.dll', 'C:\\Program Files\\ImageMagick-6.9.2-Q16-HDRI\\CORE_RL_wand_-6.Q16.dll', 'C:\\Program Files\\ImageMagick-6.9.2-Q16-HDRI\\CORE_RL_wand_-6.Q16HDRI.dll']
Both Python and ImageMagick are definitely 64-bit. And the DLL is found on the first location listed.

I did a quick test, and indeed simply trying to load that DLL fails:

Code: Select all

Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>> ctypes.cdll.CDLL(r"C:\Program Files\ImageMagick-6.9.2-Q16-HDRI\CORE_RL_magick_.dll")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Python 3.5\lib\ctypes\__init__.py", line 417, in __getattr__
    dll = self._dlltype(name)
  File "C:\Program Files\Python 3.5\lib\ctypes\__init__.py", line 347, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
So I tried to install 32-bit Python and 32-bit ImageMagick. Same result, python can't load any of the DLLs.

What's going on here? Python is definitely loading other DLLs fine, is there something special to be done for the ImageMagick DLLs?

--
Roeland

Re: Python can't register CORE_RL_wand_.dll

Posted: 2015-09-15T22:08:39-07:00
by dlemstra
Did you install the Visual C++ 2013 Redistributable Package (https://www.microsoft.com/en-us/downloa ... x?id=40784)?

Re: Python can't register CORE_RL_wand_.dll

Posted: 2015-09-16T22:32:22-07:00
by roelandsch
No I didn't have the Visual C++ 2013 Redistributable installed, but installing it didn't make a difference.

Note that:
  • msvcp120.dll is included in the installation
  • ImageMagick itself (convert, etc) runs fine without having the Visual C++ 2013 Redistributable Package installed.

Re: Python can't register CORE_RL_wand_.dll

Posted: 2015-09-17T02:21:02-07:00
by dlemstra
Did you reboot after the installation? I have only seen 'The specified module could not be found' when the C++ redistributable was not installed.

Re: Python can't register CORE_RL_wand_.dll

Posted: 2015-09-17T16:51:00-07:00
by roelandsch
I rebooted, but no change. Anyway thanks for taking the time to help me out.

Here are my current observations: Python version line:

Code: Select all

Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)] on win32
Output of ImageMagick -version:

Code: Select all

Version: ImageMagick 6.9.2-1 Q16 x64 2015-09-13 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 180031101
Features: Cipher DPC HDRI Modules OpenMP
Delegates (built-in): bzlib cairo freetype jng jp2 jpeg lcms lqr openexr pangocairo png ps rsvg tiff webp xml zlib

Re: Python can't register CORE_RL_wand_.dll

Posted: 2015-09-20T23:29:04-07:00
by roelandsch
Well, I partially figured this out. You have to change the working directory to the ImageMagick installation directory. And more annoyingly, if your python script changes the working directory afterwards, then some images will fail to load because the coder DLL can't be loaded.

I verified MAGICK_HOME is set, and the registry contains a bunch of settings under HKEY_LOCAL_MACHINE\SOFTWARE\ImageMagick\6.9.2\Q:16 pointing to the right paths.

So I'm assuming the (python module) is responsible to properly set those load paths. Is reading those paths from the registry (or the environment variable) the supported way of figuring out where the DLL's are to be found?

There is also the issue of using those FILE* objects. Python and ImageMagick are compiled using different Visual C++ versions (resp. 2015 and 2013). So you'd not be able to pass a FILE* from Python to the ImageMagick DLL, right?

[edit: whining deleted]

regards,
Roeland