我有这样的项目结构:
project-root/
source-root/
sub-package/
not_working.py
working.py
如果我在BaseEstimator
中导入working.py
:
from sklearn.base import BaseEstimator
一切都是......工作。
如果我在not_working.py
做同样的事情我会得到
Traceback (most recent call last):
File "/home/user/project-root/source-root/sub-package/not_working.py", line 3, in <module>
from sklearn.base import BaseEstimator
ImportError: No module named 'sklearn.base'; 'sklearn' is not a package
不知道问题是什么。我可以加载其他模块
这是working.py和not_working.py - 两者都有相同的代码。
import re
import numpy as np
import pandas as pd
from sklearn.base import BaseEstimator
from sklearn.pipeline import Pipeline, FeatureUnion
我可以毫无困难地导入numpy,pandas,但它不适用于sklearn包。
我已将解释器设置为我的本地Python3.5解释器
并且包似乎安装正确:
$ pip3 show sklearn
Name: sklearn
Version: 0.0
Summary: A set of python modules for machine learning and data mining
Home-page: https://pypi.python.org/pypi/scikit-learn/
Author: UNKNOWN
Author-email: UNKNOWN
License: None
Location: /usr/local/lib/python3.5/dist-packages
Requires: scikit-learn
在我们的convo之后,not_working.py
被称为sklearn.py
,因此名称的冲突意味着sklearn只是一个文件而不是我们想要的包裹。
解决方案将sklearn.py
重命名为其他内容,例如learner.py