4

When I run python script by command sudo python script.py I get error in the line

from openvino.inference_engine import IENetwork, IECore

The error is

ImportError: No module named openvino.inference_engine

But When I open the python shell and run

from openvino.inference_engine import IENetwork, IECore

I don't get this error.

What is the reason for the difference and how to fix this error?

ArunJose
  • 1,999
  • 1
  • 10
  • 33
gal leshem
  • 551
  • 1
  • 6
  • 18

1 Answers1

2

The issue you are facing is because the inference engine path is not found in the path variable. In openvino the path variables such as the path to openvino inference engine are setup for user by running the setupvars.sh shell script in the below path:

intel/openvino_2019.1.144/bin/setupvars.sh

The path variables are set specific to the user and are not present in the path variable for the sudo user. So when you run the python script using "sudo python script.py" you get the module not found error as the path variables for openvino are not rightly set for sudo.

If you open the setupvars.sh you can see all path variable are set without sudo like the below example

export PATH=~/intel/openvino_2019.2.242/python/python3.7:$PATH

**

Resolution

** To resolve your error you can use any of the two below alternatives:

1)You can run "python script.py" which could give you your expected result.

2)If you want to get this packages in "sudo python script.py" you must add openvino path to the sudo path. This can be done by editing the setupvars.sh file by changing the commands used to set paths as in the below example

eg:

export PATH=~/intel/openvino_2019.2.242/python/python3.7:$PATH

should be replaced with

sudo PATH=~/intel/openvino_2019.2.242/python/python3.7:$PATH
ArunJose
  • 1,999
  • 1
  • 10
  • 33
  • I am having the same issue. How we do resolve it for Windows? @ArunJose_Intel – Hafizur Rahman Nov 18 '20 at 05:36
  • I dont see how you have the same issue in windows. Here the issue was when a user was running opennvino with sudo. In windows there is no such thing as sudo. Are you facing difficulties when running openvino as administrator?. – ArunJose Nov 18 '20 at 06:00
  • 1
    First things first make sure you have run setupvars.bat file in the same command prompt before starting to use openvino – ArunJose Nov 18 '20 at 06:02
  • I am doing so but still having issues. For example: ``` (base) C:\Program Files (x86)\Intel\openvino_2021\bin>setupvars.bat Python 3.7.3 [setupvars.bat] OpenVINO environment initialized ``` I ran my python code https://github.com/openvinotoolkit/openvino/blob/master/inference-engine/ie_bridges/python/sample/classification_sample_async/classification_sample_async.py – Hafizur Rahman Nov 18 '20 at 06:20
  • should be an issue with python executable. make sure you are running openvino with the right python. – ArunJose Nov 18 '20 at 08:12
  • 1
    I have been running Andaconda python environment. OpenVINO has pip3 install command in the batch scripts (specially install_prerequisites.bat) which I needed to change to just pip install. So it installed all necessary components. Now it is working. – Hafizur Rahman Nov 19 '20 at 02:33
  • I am having the same issue but I installed it with pip. Is there a way to resolve this issue?@ArunJose – Sajan Kumar Apr 22 '22 at 10:55
  • what did you install with pip openvino requirements?, Are you sure you are running the same python as the one you had pip installed. Instead of "python -m pip install xyz" try "sudo python -m pip install xyz" to install to the python which is in sudo path. – ArunJose Apr 22 '22 at 18:43