Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.

OpenVINO on Mac

sso234
Novice
1,931 Views

Hi, I'm trying to run OpenVINO on MAC. for this particular code, I successfully run on Windows. But when I run on Mac, I had this error.

Can you help to advise what is possible setup issues? I read somewhere it may be due to permission or if it is linked to path, but I couldn't do much. Any advice is much appreciated. Thanks!

 

Code: 

!python classification_sample.py -i image/cat.jpeg -m models/squeezenet1.1/FP16/squeezenet1.1.xml --labels models/squeezenet1.1/FP16/squeezenet1.1.labels

 

Error:

Traceback (most recent call last):
  File "classification_sample.py", line 21, in <module>
    import cv2
ImportError: dlopen(/opt/intel/openvino_2021/python/python3/cv2.so, 2): Library not loaded: @rpath/libinference_engine.dylib
  Referenced from: /opt/intel/openvino_2021.2.185/opencv/lib/libopencv_gapi.4.5.1.dylib
  Reason: image not found

 

0 Kudos
11 Replies
Victor_G_Intel
Moderator
1,911 Views

Hello sso234,

 

Thank you for posting on the Intel® communities.

 

Your query will be best answered by our Open VINO support team. We will help you to move this post to the designated team so they can further assist you.

 

Best regards,

 

Victor G

Intel Customer Support


0 Kudos
Maksim_S_Intel
Employee
1,895 Views

Did you source setupvars.sh before running the sample? Do you run the sample in the same shell?

https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_macos.html#set-the-environment-variables

System Integrity Protection mechanism on OSX does not allow passing specific environment variables to subshells, e.g. LD_LIBRARY_PATH. So, for example, if you run a shell, source setupvars.sh in it, then run a shell script, then this script won't recieve modified LD_LIBRARY_PATH.

~ % echo $LD_LIBRARY_PATH
abc

~ % cat test.sh
echo "LD_LIBRARY_PATH is '${LD_LIBRARY_PATH}'"

~ % zsh test.sh
LD_LIBRARY_PATH is ''

 Usually if you run python directly in the shell it would recieve modified environment:

~ % python -c 'import os; print(os.environ["LD_LIBRARY_PATH"])'
abc

But some python distributions use wrapper script which would run in a subshell thus clearing necessary environment variables. Check if you run python executable directly:

~ % which python
/opt/miniconda/envs/py38_env/bin/python
~ % file $(which python)
/opt/miniconda/envs/py38_env/bin/python: Mach-O 64-bit executable x86_64

 

0 Kudos
sso234
Novice
1,865 Views

Hi Maksim,

Thank you for the reply, but I'm not sure if I followed it correctly.

From the link that you mentioned (https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_macos.html#set-the-environment-variables ) I didn't see any samples. I only executed the set environment variables and configure model optimizer. Yes, I did the source setupvars.sh.

 
~ % which python
/Users/User/opt/anaconda3/bin/python
~ % file $(which python)
/Users/User/opt/anaconda3/bin/python: Mach-O 64-bit executable x86_64

 

Just to put into context, I'm trying to run a .py file (classification_sample.py) inside a jupyter notebook using the command : 

!python classification_sample.py -i image/cat.jpeg -m models/squeezenet1.1/FP16/squeezenet1.1.xml --labels models/squeezenet1.1/FP16/squeezenet1.1.labels

Can you kindly advise what modification should I do? Is it on the OS level? Or how to set the wrapper script?

Thanks!

0 Kudos
sso234
Novice
1,858 Views

Hi Maksim,

To add on, I have the following imports inside the .py file. All are working, except for the cv2 (I created a new .py file, with try-except for each import). Are there any pointers you can provide? Thanks!

from __future__ import print_function
import sys
import os
from argparse import ArgumentParser
import cv2
import numpy as np
import logging as log
from time import time
from openvino.inference_engine import IENetwork,IECore

0 Kudos
Maksim_S_Intel
Employee
1,847 Views

I've been able to reproduce the issue when I forgot to activate my conda environment and built-in OSX Python 2 was used. setupvars.sh detected python3 executable installed somewhere else, did not produce any warning and set library paths for Python 3. Then Python 2 failed to load libraries:

bash-3.2$ . /opt/intel/openvino_2021/bin/setupvars.sh
[setupvars.sh] OpenVINO environment initialized
bash-3.2$ python -c 'import cv2'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: dlopen(/opt/intel/openvino_2021/python/python3/cv2.so, 2): Library not loaded: @rpath/libinference_engine.dylib
Referenced from: /opt/intel/openvino_2021/opencv/lib/libopencv_gapi.4.5.1.dylib
Reason: image not found
bash-3.2$ python --version
Python 2.7.16

Use python3 executable if you have it installed:

bash-3.2$ python3 -c 'import cv2'

Or setup conda environment correctly:

bash-3.2$ conda activate py37_env
(py37_env) bash-3.2$ . /opt/intel/openvino_2021/bin/setupvars.sh
[setupvars.sh] OpenVINO environment initialized
(py37_env) bash-3.2$ python -c 'import cv2'

 

0 Kudos
sso234
Novice
1,843 Views

Hi Maksim,

I don't have access to the Mac now, will try when I have access to it.

So I should setup the environment correctly? Okok, will try it out later. Thank you for your help!

bash-3.2$ conda activate py37_env
(py37_env) bash-3.2$ . /opt/intel/openvino_2021/bin/setupvars.sh
[setupvars.sh] OpenVINO environment initialized
(py37_env) bash-3.2$ python -c 'import cv2'

  

0 Kudos
sso234
Novice
1,825 Views

Hi Maksim,


Thanks for the pointers. I tried but still failed.

I tried to create a new python environment, python=3.8 and the below code doesn't give me any errors:

bash-3.2$ conda activate py37_env
(py37_env) bash-3.2$ . /opt/intel/openvino_2021/bin/setupvars.sh
[setupvars.sh] OpenVINO environment initialized
(py37_env) bash-3.2$ python -c 'import cv2'

 

But when I re-run the codes inside my jupyter notebook (I ran "jupyter notebook" within the environment), it gives me the same error again.

I also tried the earlier codes, but it doesn't work:

~ % echo $LD_LIBRARY_PATH
abc

~ % cat test.sh
echo "LD_LIBRARY_PATH is '${LD_LIBRARY_PATH}'"

~ % zsh test.sh
LD_LIBRARY_PATH is ''

Do you have any pointers that can help? Thank you so much for your help!

0 Kudos
Maksim_S_Intel
Employee
1,813 Views

Well if you want to run an external process in Jupyter notebook, you can wrap it in a shell script like this:

#!/bin/bash
. /opt/intel/openvino_2021/bin/setupvars.sh
python -c 'import cv2; print(cv2.__file__)'

Then run this script in your notebook:

!bash test.sh

 

0 Kudos
sso234
Novice
1,801 Views

Hi Maksim,

Thanks for the pointers.

With your advice, I managed to call an output using bash:

!bash test1.sh

[setupvars.sh] WARNING: Can not find OpenVINO Python module for python3.8 by path /opt/intel/openvino_2021/python/python3.8
[setupvars.sh] WARNING: OpenVINO Python environment does not set properly
[setupvars.sh] OpenVINO environment initialized
LD_LIRBARY_PATH is '/opt/intel/openvino_2021/opencv/lib:/opt/intel/openvino_2021/deployment_tools/ngraph/lib:/opt/intel/openvino_2021/deployment_tools/inference_engine/external/mkltiny_mac/lib:/opt/intel/openvino_2021/deployment_tools/inference_engine/external/tbb/lib:/opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64'
/opt/intel/openvino_2021/python/python3/cv2.so

 

However, when I modified my classification_sample.py, it doesnt work.

 

!bash classification_sample.py -i image/cat.jpeg -m models/squeezenet1.1/FP16/squeezenet1.1.xml --labels models/squeezenet1.1/FP16/squeezenet1.1.labels

[setupvars.sh] WARNING: Can not find OpenVINO Python module for python3.8 by path /opt/intel/openvino_2021/python/python3.8
[setupvars.sh] WARNING: OpenVINO Python environment does not set properly
[setupvars.sh] OpenVINO environment initialized
classification_sample.py: line 20: 
 Copyright (c) 2018 Intel Corporation

 Licensed under the Apache License, Version 2.0 (the License);
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an AS: No such file or directory
from: can't read /var/mail/__future__
classification_sample.py: line 22: import: command not found
classification_sample.py: line 23: import: command not found
from: can't read /var/mail/argparse
classification_sample.py: line 25: import: command not found
classification_sample.py: line 26: import: command not found
classification_sample.py: line 27: import: command not found
from: can't read /var/mail/time
from: can't read /var/mail/openvino.inference_engine
classification_sample.py: line 32: syntax error near unexpected token `('
classification_sample.py: line 32: `def build_argparser():'

 

Is there an equivalent script for python that I can use? (instead of !bash for ! /bin/bash, changed to !python3 for !/usr/bin/env python) 

I tried the !python3, but it doesn't work at all.

Thank you for any pointers.

0 Kudos
Maksim_S_Intel
Employee
1,754 Views

You are mixing shell script and python script, it will not work this way.

I'd recommend to take a look at the repository with Jupyter notebooks samples: https://github.com/openvinotoolkit/openvino_notebooks

0 Kudos
Syamimi_Intel
Moderator
1,710 Views

Hi Yew Meng Ng,

Thank you for your question. If you need any additional information from Intel, please submit a new question as this thread is no longer being monitored.


Regards,

Syamimi


0 Kudos
Reply