简体   繁体   English

即使似乎已安装,也无法导入 scikits-learn

[英]Cannot import scikits-learn even though it seems to be installed

Per the scikit-learn user guide, I installed scikit-learn using pip install -U scikit-learn .根据 scikit-learn 用户指南,我使用pip install -U scikit-learn

So using pip search scikit-learn , I get this search result:所以使用pip search scikit-learn ,我得到了这个搜索结果:

scikit-learn - A set of python modules for machine learning and data mining
INSTALLED: 0.12.1 (latest)

But when I go into Python and try to import sklearn , I get an ImportError: No module named sklearn .但是当我进入 Python 并尝试import sklearn ,我得到了一个ImportError: No module named sklearn This really should have just worked.这真的应该奏效。

I am using Enthought's free distribution of Python (2.7.3) on a Mac OS 10.6.8 with NumPy 1.6.1 and SciPy 0.10.1.我在带有 NumPy 1.6.1 和 SciPy 0.10.1 的 Mac OS 10.6.8 上使用 Enthought 免费分发的 Python (2.7.3)。 Yes, I'm aware that EPD Free comes with scikit-learn but pip should have upgraded my version so that I can actually use scikit-learn.是的,我知道 EPD Free 带有 scikit-learn,但 pip 应该升级我的版本,以便我可以实际使用 scikit-learn。

Got same problem, @Alan gave correct solution but hard way.遇到同样的问题,@Alan 给出了正确的解决方案,但方法很困难。 Here are easy steps to resolve issue, as i am on mac osx, giving steps for same.这是解决问题的简单步骤,因为我在 mac osx 上,给出了相同的步骤。

Ameys-Mac-mini:~ amey$ python --version
Python 2.7.2
Ameys-Mac-mini:~ amey$ cd /Library/Python/2.7/site-packages/
Ameys-Mac-mini:site-packages amey$ brew install gcc
Ameys-Mac-mini:site-packages amey$ sudo pip install -t . numpy scipy scikit-learn 

Thanks folks (see comment thread under the question)!谢谢大家(请参阅问题下的评论线程)! It turns out that I have two versions of Python under my Mac's /Library/Frameworks/Python.framework directory tree: 2.7 (came with OSX) and 7.3 (installed by EPD Free).事实证明,我在 Mac 的 /Library/Frameworks/Python.framework 目录树下有两个版本的 Python:2.7(随 OSX 一起提供)和 7.3(由 EPD Free 安装)。

It turns out pip put scikit-learn under 2.7 when I really wanted it under 7.3.事实证明pip把 scikit-learn 放在了 2.7 之下,而我真的想要它在 7.3 之下。

Changing directories to site-packages under the desired version of Python, and invoking pip install -t . {package-name}将目录更改为所需 Python 版本下的站点包,并调用pip install -t . {package-name} pip install -t . {package-name} suffices to install package-name under the desired version of Python. pip install -t . {package-name}足以在所需的 Python 版本下安装 package-name。

POSTLUDE (Feb 2021): Looking back on this question from almost 9 years ago, I think I was running into a version of this XKCD comic. POSTLUDE(2021 年 2 月):回顾大约 9 年前的这个问题,我想我遇到了这个 XKCD 漫画的一个版本。

python中的依赖管理地狱

Nowadays, for dependency management of Python data engineering libraries like scikit, I'm happy with just using conda and pyenv .如今,对于Python数据工程库,例如scikit依赖管理,我很高兴与仅仅使用畅达pyenv

In my case, my python extension has installed all in就我而言,我的 python 扩展已全部安装在

/Library/Python/2.7/site-packages/ 

After I use the command given by the official site我使用官网给出的命令后

pip install -U numpy scipy scikit-learn

the scikit-learn package was actually installed in my scikit-learn 包实际上安装在我的

/usr/local/lib/python2.7/site-packages

So I copied all the packages in second to the first directory, then I can import the sklearn package.所以我把second里的所有包都复制到了第一个目录下,然后就可以导入sklearn包了。

For future reference:备查:

easy_install -U statsmodels easy_install -U statsmodels

I had the same issue and I could figure out that python versions were different.我有同样的问题,我可以弄清楚 python 版本是不同的。 I followed this answer .我跟着这个答案

On Zeppelin page, go to the settings, Intepreter settings and change your python to python3.在 Zeppelin 页面上,转到设置、解释器设置并将您的 python 更改为 python3。

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

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