ModuleNotFoundError: No module named 'common.utils' - 解决方法
错误提示:
'ModuleNotFoundError: No module named 'common.utils''
原因:
这个错误提示说明找不到名为'common.utils'的模块。这可能是由于该模块未安装或者未在当前路径下。
解决方法:
-
检查是否安装了'common.utils'模块
如果该模块未安装,可以使用以下命令安装:
pip install common.utils
2. **检查该模块是否在当前路径下**
如果'common.utils'模块是一个自定义模块,请确保它位于当前代码所在的目录下,或者位于系统环境变量PYTHONPATH中指定的目录下。
- 将该模块复制到当前代码目录下。
- 将该模块所在目录添加到系统环境变量PYTHONPATH中。
3. **检查代码中是否正确引用了该模块**
确保代码中引用'common.utils'模块的路径正确。
**代码示例:**
```python
import time
from common.utils import plot_learning_curve # 确保路径正确
from sklearn.model_selection import ShuffleSplit
cv = ShuffleSplit(n_splits=10, test_size=0.2, random_state=0)
title = 'Learning Curves (degree={0}, penalty={1})'
start = time.clock()
plt.figure(figsize=(12, 4), dpi=144)
plot_learning_curve(plt, GaussianNB(), 'Learning Curves', data, digits.target, ylim=(0.7, 1.01), cv=cv)
print('elaspe: {0:.6f}'.format(time.clock()-start))
其他可能的原因:
- 模块名称拼写错误
- 模块版本不兼容
- 代码中存在语法错误
建议:
- 使用pip list命令查看已安装的模块列表,确认'common.utils'模块是否已安装。
- 使用IDE的代码补全功能,避免拼写错误。
- 检查代码中引用该模块的路径是否正确。
- 检查代码中是否存在语法错误。
原文地址: https://www.cveoy.top/t/topic/lSoE 著作权归作者所有。请勿转载和采集!