Python ModuleNotFoundError: 没有名为“utils”的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49545142/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ModuleNotFoundError: No module named 'utils'
提问by
I'm trying to run the object_detection API in Tensorflow using my webcam as an input.
我正在尝试使用我的网络摄像头作为输入在 Tensorflow 中运行 object_detection API。
The error says: "from utils import label_map_util ModuleNotFoundError: No module named 'utils'"
错误说:“from utils import label_map_util ModuleNotFoundError: No module named 'utils'”
Which relates to the lines:
这与以下几行有关:
from utils import label_map_util
from utils import visualization_utils as vis_util
I've tried "pip install util" appears to work but doesn't solve the problem. I have also reinstalled multiple versions of protobuf as other questions online appear to have this as the solution. I don't get any errors when I install protoc so I don't think this is the issue.
我试过“pip install util”似乎工作但没有解决问题。我还重新安装了 protobuf 的多个版本,因为其他在线问题似乎都以此作为解决方案。安装 protoc 时我没有收到任何错误,所以我认为这不是问题所在。
I'm using python 3.6 on windows 10 with tensorflow-gpu.
我在带有 tensorflow-gpu 的 Windows 10 上使用 python 3.6。
采纳答案by drec4s
What folder are you running your python script from?
你从哪个文件夹运行你的python脚本?
To be able to access the 'utils' module directly, you need to be running the script inside the <models-master>\research\object_detection
folder.
为了能够直接访问“utils”模块,您需要在<models-master>\research\object_detection
文件夹内运行脚本。
回答by Kamble Tanaji
Instead of running script inside object detection folder append the path of tensorflow object detection in your script by writing
import sys sys.path.append('PATH_TO_TENSORFLOW_OBJECT_DETECTION_FOLDER')
e.g 'PATH_TO_TENSORFLOW_OBJECT_DETECTION_FOLDER' in my ubuntu system is
/home/dc-335/Documents/Softwares/tensorflow/models/research/object_detection
Cheers, You done it !!
不要在对象检测文件夹中运行脚本,而是通过编写在脚本中附加 tensorflow 对象检测的路径
import sys sys.path.append('PATH_TO_TENSORFLOW_OBJECT_DETECTION_FOLDER')
例如,我的 ubuntu 系统中的“PATH_TO_TENSORFLOW_OBJECT_DETECTION_FOLDER”是
/home/dc-335/Documents/Softwares/tensorflow/models/research/object_detection
干杯,你做到了!!
回答by sailfish009
add object_detection to the front of utils:
将 object_detection 添加到 utils 的前面:
# from utils import label_map_util
# from utils import visualization_utils as vis_util
from object_detection.utils import label_map_util
from object_detection.utils import visualization_utils as vis_util
回答by Lovesh Dongre
I used a quicker method to fix it.
我使用了一种更快的方法来修复它。
I copied the utilsfolder from models\research\object_detectionand pasted it within the same directory as the python file which required utils
我从models\research\object_detection复制了utils文件夹并将其粘贴到与需要utils的 python 文件相同的目录中