我对python不是很熟悉。我在 python 3.5 中使用 scikit-learn。这可能是一个幼稚的问题。
在 site-pacakges\sklearn 文件夹中,我可以看到一个 __init__.py 文件。所以 sklearn 应该是一个 package 根据 doc .但是当我运行下面的代码时,它说 sklearn 是一个 module。
In [21]: sklearn
Out[21]: <module 'sklearn' from '/home/python35/lib/site-packages/sklearn/__init__.py'>
不应该是 package 'sklearn' 而不是 module 'sklearn' 吗?
请您参考如下方法:
所有 Python 包都是 module 类型。
来自docs :
Technically, a package is a Python module with a
__path__attribute.
>>> import numpy # numpy package
>>> type(numpy)
<type 'module'>
>>> numpy.__path__
['/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy']
>>>
>>> import collections # collections module
>>> collections.__path__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '__path__'
