导入sklearn失败 - 与numpy版本冲突?

时间:2016-03-16 07:10:48

标签: python-2.7 numpy scikit-learn

我正在尝试在交互式python环境中导入sklearn模块,但是我收到此错误消息:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/sklearn/__init__.py", line 57, in <module>
    from .base import clone
  File "/Library/Python/2.7/site-packages/sklearn/base.py", line 11, in <module>
from .utils.fixes import signature
  File "/Library/Python/2.7/site-packages/sklearn/utils/__init__.py", line 10, in <module>
from .murmurhash import murmurhash3_32
  File "numpy.pxd", line 155, in init sklearn.utils.murmurhash (sklearn/utils/murmurhash.c:5029)
ValueError: numpy.dtype has the wrong size, try recompiling

我在某处读到这可能是一个问题,因为scikit-learn是针对较旧版本的numpy编译的,但我试图卸载并重新安装numpy和scikit-learn(和scipy以确定)和问题依然存在。

这些是我的python模块:

giacomopoli$ pip freeze
Warning: cannot find svn location for setuptools===0.6c12dev-r88846
altgraph==0.10.1
appnope==0.1.0
attrs==15.2.0
backports-abc==0.4
backports.ssl-match-hostname==3.5.0.1
bdist-mpkg==0.4.4
beautifulsoup4==4.4.1
bonjour-py==0.3
certifi==2016.2.28
cssselect==0.9.1
decorator==4.0.9
functools32==3.2.3.post2
gnureadline==6.3.3
ipykernel==4.3.1
ipython==4.1.2
ipython-genutils==0.1.0
ipywidgets==4.1.1
Jinja2==2.8
jsonschema==2.5.1
jupyter==1.0.0
jupyter-client==4.1.1
jupyter-console==4.1.1
jupyter-core==4.0.6
lxml==3.5.0
macholib==1.5
MarkupSafe==0.23
matplotlib==1.1.1
mistune==0.7.2
modulegraph==0.10.1
nbconvert==4.1.0
nbformat==4.0.1
notebook==4.1.0
numpy==1.10.4
path.py==8.1.2
pexpect==4.0.1
pickleshare==0.6
protobuf==3.0.0b2
ptyprocess==0.5.1
py2app==0.7.1
pyasn1==0.1.9
pyasn1-modules==0.0.8
Pygments==2.1.3
PyInstaller==3.1.1
pyobjc-core==2.3.2a0
pyobjc-framework-AddressBook==2.3.2a0
pyobjc-framework-AppleScriptKit==2.3.2a0
pyobjc-framework-AppleScriptObjC==2.3.2a0
pyobjc-framework-Automator==2.3.2a0
pyobjc-framework-CFNetwork==2.3.2a0
pyobjc-framework-Cocoa==2.3.2a0
pyobjc-framework-Collaboration==2.3.2a0
pyobjc-framework-CoreData==2.3.2a0
pyobjc-framework-CoreLocation==2.3.2a0
pyobjc-framework-CoreText==2.3.2a0
pyobjc-framework-DictionaryServices==2.3.2a0
pyobjc-framework-ExceptionHandling==2.3.2a0
pyobjc-framework-FSEvents==2.3.2a0
pyobjc-framework-InputMethodKit==2.3.2a0
pyobjc-framework-InstallerPlugins==2.3.2a0
pyobjc-framework-InstantMessage==2.3.2a0
pyobjc-framework-InterfaceBuilderKit==2.3.2a0
pyobjc-framework-LatentSemanticMapping==2.3.2a0
pyobjc-framework-LaunchServices==2.3.2a0
pyobjc-framework-Message==2.3.2a0
pyobjc-framework-OpenDirectory==2.3.2a0
pyobjc-framework-PreferencePanes==2.3.2a0
pyobjc-framework-PubSub==2.3.2a0
pyobjc-framework-QTKit==2.3.2a0
pyobjc-framework-Quartz==2.3.2a0
pyobjc-framework-ScreenSaver==2.3.2a0
pyobjc-framework-ScriptingBridge==2.3.2a0
pyobjc-framework-SearchKit==2.3.2a0
pyobjc-framework-ServiceManagement==2.3.2a0
pyobjc-framework-SyncServices==2.3.2a0
pyobjc-framework-SystemConfiguration==2.3.2a0
pyobjc-framework-WebKit==2.3.2a0
pyobjc-framework-XgridFoundation==2.3.2a0
pyOpenSSL==0.13
PyRSS2Gen==1.0.0
python-dateutil==1.5
pytz===2012d
pyzmq==15.2.0
qtconsole==4.2.0
queuelib==1.4.2
scikit-learn==0.17.1
scipy==0.17.0
Scrapy==1.0.5
selenium==2.52.0
service-identity==16.0.0
simplegeneric==0.8.1
singledispatch==3.4.0.3
six==1.10.0
tensorflow==0.7.1
terminado==0.6
tornado==4.3
traitlets==4.1.0
Twisted==12.2.0
w3lib==1.13.0
xattr==0.6.4
zope.interface==3.8.0

我有Python 2.7和OSX 10.9.5。 为了让事情顺利,我该怎么做?

1 个答案:

答案 0 :(得分:0)

我明白了。我安装了多个版本的python(2.3,2.5,2.6,2.7)和Numpy的多个版本。交互式shell中使用的那个是numpy 1.6。我把它们全部删除了,并用numpy安装了新的,现在它可以工作了。