我在Windows 10上使用Python 3.6.8
我使用pip安装了tensorflow, keras 和 utils。
pip install tensorflow
安装了版本 2.0.0pip install keras
安装了版本 2.3.1pip install utils
但它没有显示我安装的版本。
这是我的头部代码:
from keras.preprocessing import imagefrom PIL import Imagefrom keras.models import model_from_json, load_modelimport numpy as npimport cv2from datetime import datetimeimport osimport randomimport stringfrom utils.datasets import get_labelsfrom utils.inference import apply_offsetsfrom utils.inference import load_detection_modelfrom utils.preprocessor import preprocess_input
这是我的错误:
from utils.datasets import get_labels
ModuleNotFoundError: 未找到名为’utils.datasets’的模块
为什么我会得到这个错误?如何修复它?顺便说一下,这段代码是由之前的程序员编写的,我需要修改它。但我连运行都做不到。我对Python不太熟练,我才刚开始学。
我在谷歌上搜索的所有链接都已经变紫色了,但我似乎找不到任何解决方案。
编辑
建议的答案(ImportError: No module named datasets)不符合我的需求。我在utils模块上遇到了麻烦。因为当我注释掉from utils.datasets import get_labels
这一行时
错误出现在下一行:
ModuleNotFoundError: 未找到名为’utils.inference’的模块
回答:
你提供的代码想要导入的utils模块是oarriaga/face_classification项目的一部分。
通过pip安装的utils
模块是一个完全不同的包,所以你不应该通过pip
安装。你的代码试图从这个包中导入模块,但显然它没有这些模块。这就是错误信息出现的原因。
所以你需要做的是pip uninstall utils
,然后如果你的项目目录结构是完整的,上述代码将导入face_classification
包的模块。