简体   繁体   English

Python:为什么不加载此子模块?

[英]Python: Why isn't this submodule being loaded?

I installed scikit-learn with pip ( pip install -U scikit-learn ). 我用pip安装了scikit-learn( pip install -U scikit-learn )。 I then went to ipython and ran import sklearn , but if I then try to load any modules, they aren't found. 然后,我去了ipython并运行import sklearn ,但是如果我随后尝试加载任何模块,都找不到它们。 In particular, the tab completion of sklearn doesn't seem correct: 特别是,sklearn的制表符补全似乎不正确:

In [2]: sklearn.
sklearn.base          sklearn.clone         sklearn.externals     sklearn.re            sklearn.setup_module  sklearn.sys           sklearn.test          sklearn.warnings 

Any idea what's going on here? 知道这里发生了什么吗? Other modules load fine. 其他模块加载正常。 For example, numpy works normally. 例如,numpy正常工作。

Import the submodule you want to use explicitly: 导入要明确使用的子模块:

import sklearn.<submodule>
print sklearn.<submodule>.function()

or 要么

from sklearn.<submodule> import function
print function()

In large python packages, oftentimes the submodules need to be explicitly imported. 在大型python包中,通常需要显式导入子模块。 This is so that the user can pick and choose what to import without importing the entire package (which can negatively affect startup time). 这样一来,用户可以选择要导入的内容而无需导入整个程序包(这可能会对启动时间产生负面影响)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM