PJD
PJD

Reputation: 53

Conflicting imports of the MATLAB engine and Imatest IT

I am using Imatest IT (v5.0.1) and need to use Imatest IT tests with my Python code, however, my Python code also interfaces with MATLAB’s (2017b) Python API and there seems to be a conflict.

You can see below that simply trying to import ImatestLibrary after importing the matlab.engine results in an exception. Just importing one or the other causes no problem.

import matlab.engine
from imatest.it import ImatestLibrary

Exception caught during initialization of Python interface. Details: DLL load failed: The specified procedure could not
be found.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python34\lib\site-packages\imatest\it.py", line 6, in <module>
    import imatest.library
  File "C:\Python34\lib\site-packages\imatest\library\__init__.py", line 279, in <module>
    _pir.import_cppext()
  File "C:\Python34\lib\site-packages\imatest\library\__init__.py", line 272, in import_cppext
    self.cppext_handle = importlib.import_module("matlabruntimeforpython" + self.interpreter_version)
  File "C:\Python34\lib\importlib\__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: DLL load failed: The specified procedure could not be found.

Is there a way to overcome this issue?

Upvotes: 1

Views: 356

Answers (3)

PJD
PJD

Reputation: 53

The workaround to this I used was to create new processes using Python's multiprocessing module. The processes would use either the MATLAB libraries or the Imatest libraries. An extra layer of code but it works.

Upvotes: 0

anjhinz
anjhinz

Reputation: 41

Which version of python are you using? It's possible it's not one of Matlabs supported versions for 2017b, which are limited. I forget exactly which but I think 2.7, 3.3, 3.4, and possibly 3.5

Upvotes: 0

According to the documentation of the Imatest Python interface regarding importing imatest.it:

Behind the scenes, the ImatestLibrary constructor will start up the Matlab MCR Runtime and load all the IT libraries into memory.

This suggests that imatest itself meddles with the state of the MATLAB engine. While the order of imports usually doesn't matter, occasionally certain imports should happen before others for proper initialization, when modules imported later rely on modules imported earlier (for instance, importing matplotlib first and setting a backend before importing pyplot that would use said backend).

So my only suggestion is to try switching the order of imports to see if that helps. If it doesn't you're out of luck (as far as Stack Overflow is concerned): both MATLAB and Imatest are expensive proprietary (and even closed source) products so you should file bug reports to either or both of them, because nobody else will be able to tell if and how the conflict could be fixed.

Upvotes: 1

Related Questions