不能使用 scikit-learn - “AttributeError: 'module' object has no attribute ..." [英] can't use scikit-learn - "AttributeError: 'module' object has no attribute ..."
问题描述
我正在尝试遵循 本教程 scikit-learn(线性回归).
I'm trying to follow this tutorial of scikit-learn (linear regression).
我已经通过pip install -U scikit-learn
安装了scikit,我使用的是python 2.7和Ubuntu 13.04
I've installed scikit through pip install -U scikit-learn
, I use python 2.7 and Ubuntu 13.04
当我尝试运行第一行代码时,出现错误,并且每次尝试使用 scikit-learn 运行任何代码时都会发生这种情况.
When I try to run the first lines of code there I get an error and it happens every time I'm trying to run anything with scikit-learn.
import pylab as pl
import numpy as np
from sklearn import datasets, linear_model
# Load the diabetes dataset
diabetes = datasets.load_diabetes()
我得到以下信息:
AttributeError: 'module' object has no attribute 'load_diabetes'
当我尝试时:
regr = linear_model.LinearRegression()
我明白了:
AttributeError: 'module' object has no attribute 'LinearRegression'
在我看来,要么是我使用的包有误(但我是从他们的教程中复制的),要么是我安装了错误的东西(但包已成功加载).
It seems to me that it's either I'm using the package wrong (but I've copied from their tutorial), or I've installed something wrong (but the package is loaded successfully).
有人可以帮忙吗?
推荐答案
好的.. 终于找到了.. 把它贴在这里以防有人遇到同样的问题.
OK.. Found it finally.. Posting it here in case someone will get into the same problem.
我在不同的目录中有另一个版本的 sklearn(可能是因为 apt-get install).它以某种方式部分安装,但它已加载.
I had another version of sklearn (probably because of apt-get install) in a different directory. It was partially installed somehow but it was the one that got loaded.
确保查看您的 pip
脚本的输出以查看它安装包的位置,当您从 python 加载它时,检查 sklearn.__path__
以查看安装位置是从那里拿来的吗.
Make sure to look at your pip
script's output to see where does it install the package, and when you load it from python, check sklearn.__path__
to see where is it taking it from.
这篇关于不能使用 scikit-learn - “AttributeError: 'module' object has no attribute ..."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!