Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Celi__Joseph
Beginner
696 Views

Unable to import cv2 on Mac

I just installed the latest OpenVINO toolkit for Mac.  I'm getting the following error

 

[setupvars.sh] OpenVINO environment initialized

$ python

Python 3.6.1 (default, Sep 24 2019, 10:11:07) 

[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.4)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> import cv2

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

ImportError: dlopen(/opt/intel/openvino_2020.1.023/python/python3/cv2.so, 2): Library not loaded: @rpath/libopencv_ml.4.2.dylib

  Referenced from: /opt/intel/openvino_2020.1.023/python/python3/cv2.so

  Reason: image not found

0 Kudos
12 Replies
Celi__Joseph
Beginner
696 Views

I thought I figured it out but was wrong so I am deleting what I thought fixed the issue.

Maksim_S_Intel
Employee
696 Views

Please check if your installation is complete, does file "/opt/intel/openvino_2020.1.023/opencv/lib/libopencv_ml.4.2.dylib" exist?

Celi__Joseph
Beginner
696 Views

The file does exist but not in that directory.  This could be due to the fact that I tried all 3 installation types and the last installation type was "user"

Joseph-Celi-MBP:lib josephceli$ pwd

/Users/josephceli/intel/openvino_2020.1.023/opencv/lib

Joseph-Celi-MBP:lib josephceli$ ll libopencv_ml.4.2.dylib

lrwxrwxr-x  1 josephceli  staff  24 Jan 27 10:56 libopencv_ml.4.2.dylib -> libopencv_ml.4.2.0.dylib

Maksim_S_Intel
Employee
696 Views

So you have to activate environment for installation in user directory: ". /Users/josephceli/intel/openvino_2020.1.023/bin/setupvars.sh"

Celi__Joseph
Beginner
696 Views

Maksim,

Yes, I had been doing that.

Joseph-Celi-MBP:opencv josephceli$ . /Users/josephceli/intel/openvino_2020.1.023/bin/setupvars.sh

[setupvars.sh] OpenVINO environment initialized

Joseph-Celi-MBP:opencv josephceli$ python get_ver.py 

Traceback (most recent call last):

  File "get_ver.py", line 1, in <module>

    import cv2

ImportError: dlopen(/Users/josephceli/intel/openvino_2020.1.023/python/python3/cv2.so, 2): Library not loaded: @rpath/libopencv_ml.4.2.dylib

  Referenced from: /Users/josephceli/intel/openvino_2020.1.023/python/python3/cv2.so

  Reason: image not found

Maksim_S_Intel
Employee
696 Views

I can not reproduce the issue:

$ . intel/openvino_2020.1.023/bin/setupvars.sh 
[setupvars.sh] OpenVINO environment initialized
$ python3
Python 3.7.3 (default, Jun 19 2019, 07:38:49) 
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> 

What is your OS version? Check LD_LIBRARY_PATH and DYLD_LIBRARY_PATH environment variables contents, at least one of them should contain path to opencv/lib directory. Check sizes of installed files.

Celi__Joseph
Beginner
696 Views

macOS Mojave - Version 10.14.6 

checking library paths now and will report back

Celi__Joseph
Beginner
696 Views

Joseph-Celi-MBP:~ josephceli$ . /Users/josephceli/intel/openvino_2020.1.023/bin/setupvars.sh

[setupvars.sh] OpenVINO environment initialized

Joseph-Celi-MBP:~ josephceli$ echo $LD_LIBRARY_PATH

/Users/josephceli/intel//openvino_2020.1.023/opencv/lib:/Users/josephceli/intel//openvino_2020.1.023/deployment_tools/ngraph/lib:/Users/josephceli/intel//openvino_2020.1.023/deployment_tools/inference_engine/external/mkltiny_mac/lib:/Users/josephceli/intel//openvino_2020.1.023/deployment_tools/inference_engine/external/tbb/lib:/Users/josephceli/intel//openvino_2020.1.023/deployment_tools/inference_engine/lib/intel64:

Joseph-Celi-MBP:~ josephceli$ echo $DYLD_LIBRARY_PATH

/Users/josephceli/intel//openvino_2020.1.023/deployment_tools/inference_engine/external/mkltiny_mac/lib:/Users/josephceli/intel//openvino_2020.1.023/deployment_tools/inference_engine/external/tbb/lib:/Users/josephceli/intel//openvino_2020.1.023/deployment_tools/inference_engine/lib/intel64:

Joseph-Celi-MBP:~ josephceli$ find . -name libopencv_ml.4.2.dylib 2>/dev/null

./intel/openvino_2020.1.023/opencv/lib/libopencv_ml.4.2.dylib

Joseph-Celi-MBP:~ josephceli$ pwd

/Users/josephceli

Max_L_Intel
Moderator
696 Views

Hello Joseph.

Can you please try the workaround from this thread - https://github.com/opencv/opencv/issues/14353

Celi__Joseph
Beginner
696 Views

Just noticed this last update.  @Max - I will try the workaround and report back.

Celi__Joseph
Beginner
696 Views

@Max - I appreciate the link but am still unsure how to take the information from those links and apply it to my machine to get around the fact that the OpenCV dynamic link library cannot be found at runtime.  While the link above describes a similar problem from the Java environment it certainly appears to be exactly what I am seeing.  I tried to manually update my environment, using the following snippet from the links provided above

 

if sys.platform == 'darwin': # https://github.com/opencv/opencv/issues/14351

if env is None:

env = os.environ.copy()

if 'DYLD_LIBRARY_PATH' in env:

env['OPENCV_SAVED_DYLD_LIBRARY_PATH'] = env['DYLD_LIBRARY_PATH']

 

I still see the same error 

 

Traceback (most recent call last):

  File "multi_camera_multi_person_tracking.py", line 22, in <module>

    import cv2 as cv

ImportError: dlopen(/Users/josephceli/intel/openvino_2020.1.023/python/python3/cv2.so, 2): Library not loaded: @rpath/libopencv_ml.4.2.dylib

  Referenced from: /Users/josephceli/intel/openvino_2020.1.023/python/python3/cv2.so

  Reason: image not found

 

Thanks for your support

Max_L_Intel
Moderator
696 Views

Hi Joseph.

Can you please try it with "python3" alias instead of just "python"? Or you could also try upgrading python over to 3.7 version.
I see the same behavior on my machine with "python" as python 2.7, but everything's fine with "python3" as python 3.7.

Best regards, Max.

Reply