简体   繁体   English

python ImportError Openvino by script 和 shell

[英]python ImportError Openvino by script and by shell

When I run python script by command sudo python script.py I get error in the line当我通过命令sudo python script.py运行 python 脚本时,我在行中出现错误

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但是当我打开 python shell 并运行时

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?差异的原因是什么以及如何解决此错误?

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:在 openvino 中,通过在以下路径中运行 setupvars.sh shell 脚本为用户设置路径变量,例如 openvino 推理引擎的路径:

intel/openvino_2019.1.144/bin/setupvars.sh英特尔/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.路径变量是针对用户设置的,并且不存在于 sudo 用户的路径变量中。 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.因此,当您使用“ sudo python script.py ”运行 python 脚本时,您会收到模块未找到错误,因为 openvino 的路径变量未正确设置为 sudo。

If you open the setupvars.sh you can see all path variable are set without sudo like the below example如果您打开 setupvars.sh,您可以看到所有路径变量都设置为没有 sudo,如下例所示

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. 1)您可以运行“ python script.py ”,它可以给您预期的结果。

2)If you want to get this packages in " sudo python script.py " you must add openvino path to the sudo path. 2)如果你想在“ sudo python script.py ”中获取这个包,你必须在sudo路径中添加openvino路径。 This can be done by editing the setupvars.sh file by changing the commands used to set paths as in the below example这可以通过更改用于设置路径的命令来编辑 setupvars.sh 文件来完成,如下例所示

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM