Scipy错误:numpy.dtype大小更改,可能表示二进制不兼容(及相关异常行为)
我在OS X 10.9.4上安装numpy、scipy和scikit-learn时,遇到了一个错误,提示“numpy.dtype大小发生变化,可能表示二进制不兼容”。
这是我构建这个项目时做的步骤:
mkvirtualenv thm
workon thm
pip install numpy scipy pandas ipython # and some other stuff
cd /path/to/our/repo
# run tests
下面是一个相关警告的追踪摘录(因为我们在测试开始时使用了warnings.simplefilter('error')
,所以这个警告变成了错误):
======================================================================
ERROR: Failure: RuntimeWarning (numpy.dtype size changed, may indicate binary in
compatibility)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/ben/.virtualenvs/thm/lib/python2.7/site-packages/nose/loader.py",
line 414, in loadTestsFromName
addr.filename, addr.module)
File "/Users/ben/.virtualenvs/thm/lib/python2.7/site-packages/nose/importer.py
", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/Users/ben/.virtualenvs/thm/lib/python2.7/site-packages/nose/importer.py
", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/Users/ben/code/thm/alpha/prosper/base/stats/test_auc.py", line 3, in <m
odule>
import sklearn.metrics
File "/Users/ben/.virtualenvs/thm/lib/python2.7/site-packages/sklearn/metrics/
__init__.py", line 6, in <module>
from .metrics import (accuracy_score,
File "/Users/ben/.virtualenvs/thm/lib/python2.7/site-packages/sklearn/metrics/metrics.py", line 27, in <module>
from scipy.spatial.distance import hamming as sp_hamming
File "/Users/ben/.virtualenvs/thm/lib/python2.7/site-packages/scipy/spatial/__init__.py", line 90, in <module>
from .ckdtree import *
File "__init__.pxd", line 155, in init scipy.spatial.ckdtree (scipy/spatial/ckdtree.c:20570)
RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility
有人告诉我,这个警告是因为scipy是用一个和我安装的numpy版本不同的版本编译的。不过,我是通过pip安装它们的,按照我认为的标准方式来做的,所以我觉得这不应该是个问题。
奇怪的是,虽然运行我们整个测试套件(通过python -m unittest discover
)会出现这些错误,但单独运行每个测试(通过python -m unittest <module>
)却没问题。
根据测试,这里有一些相关的版本信息:
numpy version 1.9.0 (rev 07601a64cdfeb1c0247bde1294ad6380413cab66)
scipy version 0.14.0 (built against numpy 1.9.0)
sklearn version 0.15.2
pandas version 0.14.1
如果需要更多信息,我很乐意提供!
1 个回答
15
你是怎么构建sklearn 0.14.1的?你是用和scipy一样的numpy版本来构建的吗?
最近版本的scikit-learn、scipy和numpy都有现成的安装包。特别是scikit-learn 0.15.2应该可以和numpy 1.7及以上版本兼容。我觉得scipy 0.14.0也是这样,但你说你是从源代码自己构建的,这不是pip默认的做法(pip应该直接安装现成的whl包)。
编辑:你有没有试过这样做:
pip install -U scipy scikit-learn pandas
来确保你使用的是这些包的最新稳定版本的whl文件?
编辑:下面的评论里有实际有效的答案,这也是为什么这个答案被接受的原因。也就是说:
pip uninstall -y scipy scikit-learn
pip install --no-binary scipy scikit-learn