Calling third-party Python modules installed with homebrew from Matlab?

3 次查看(过去 30 天)
I've installed the OpenCV library for Python using homebrew. I've successfully used it within Python for weeks, but now I'd like to attempt calling OpenCV functions from Matlab. Currently I'm able to call built-in libraries without issue, but not third-party modules. How can I get this working? Thanks!
  1 个评论
the cyclist
the cyclist 2015-6-27
Leaving this comment only so I can easily find this question again. Several months ago, I did some of this exploration, and I think I ended up achieving only what you have.

请先登录,再进行评论。

采纳的回答

Robert Snoeberger
Robert Snoeberger 2015-6-28
Use the import_module function from importlib when you want more information about an import failure. If import fails, then you will get the Python exception. The exception will give you more information about the cause of the failure.
I can reproduce the import failure:
>> py.importlib.import_module('cv2')
Python Error: dlopen(/usr/local/Cellar/opencv3/3.0.0/lib/python2.7/site-packages/cv2.so, 2): Library not loaded:
/usr/local/lib/libtiff.5.dylib
Referenced from: /usr/local/Cellar/opencv3/3.0.0/lib/libopencv_imgcodecs.3.0.dylib
Reason: Incompatible library version: libopencv_imgcodecs.3.0.dylib requires version 8.0.0 or later, but libtiff.5.dylib provides
version 6.0.0
>>
As you can see in the error message, the cause of the failure is an incompatible library version. The library that is causing the problem is libtiff.5.dylib. I have two versions of the library, 1) a version located at /usr/local/lib/libtiff.5.dylib that Python normally uses and 2) another version located at /Applications/MATLAB_R2014b.app/bin/maci64/libtiff.5.dylib that MATLAB uses. When you call opencv functions from MATLAB, the MATLAB version of the library is picked up and it is incompatible.
Related questions have been asked on MATLAB Answers. See here and here .
  1 个评论
Dylan Brown
Dylan Brown 2015-6-28
>> py.importlib.import_module('cv2')
Python Error: dlopen(/usr/local/lib/python2.7/site-packages/cv2.so, 2): Symbol not found:
__ZN2cv14chamerMatchingERNS_3MatES1_RNSt3__16vectorINS3_INS_6Point_IiEENS2_9allocatorIS5_EEEENS6_IS8_EEEERNS3_IfNS6_IfEEEEdidiiidddd
Referenced from: /usr/local/lib/python2.7/site-packages/cv2.so
Expected in: /Applications/MATLAB_R2014b.app/bin/maci64/libopencv_contrib.2.4.dylib
in /usr/local/lib/python2.7/site-packages/cv2.so
Thanks! This is the exception output I get. Is there any linker setting I can change to get around the problem?

请先登录,再进行评论。

更多回答(0 个)

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by