我在Mac上,按这个顺序安装了numpy
和sklearn
。现在,我面对的这些错误已经被多次提到:
sklearn "numpy.dtype has the wrong size, try recompiling" in both pycharm and terminal
ValueError: numpy.dtype has the wrong size, try recompiling
ImportError in importing from sklearn: cannot import name check_build
因此,我尝试通过卸载numpy
并重新安装以前的版本来修正此错误。
1)sudo pip install --upgrade numpy
..给出权限错误
...OSError: [Errno 1] Operation not permitted: '/tmp/pip-OVY0Vq-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy-1.8.0rc1-py2.7.egg-info'...
2)我尝试了brew uninstall numpy
,但是import numpy
即使在shell重新启动之后仍然可以工作。
我唯一能想到的是手动删除所有的numpy
文件,在Mac seeem上可以在
sudo rm -rf /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy
……但即使这样也给了我一个许可错误。给什么?
为了解决这个问题,我做了如下的工作:(注意,我并不完全清楚这些解决了问题中的哪一个,因为我没有进行彻底的测试)。
1)在python.org上安装python而不是Mac的愚蠢版本
2)重新安装所有模块,如
numpy
、scipy
、matplotlib
、sklearn
,并根据此源运行此代码:hash -r python
,因为它不会使python使用模块的缓存版本。3)然后,我意识到我有这个问题:https://github.com/scipy/scipy/issues/5093。为了解决这个问题,我必须确保使用
python -m pip install scipy='0.15.0'
而不是仅仅使用pip install scipy='0.15.0'
来安装scipy
模块,因为这解决了基于这个源的问题:Can't load Python modules installed via pip from site-packages directory。因此,总而言之,由
pip
安装的内容和从终端执行python
时导入的内容之间确实有很大的不同。因此,为了确保使用pip将模块安装到特定的python中,可以使用python -m pip install <package name>
。当我尝试在MAC上安装pandas时,我也会收到这个命令,但是下面的命令可以帮助我解决这个问题。以下命令将忽略以前安装的任何版本。虽然不确定它是否真正解决了问题,但您也可以尝试:
我猜你在用MAC操作系统。 我做了一个解决方案,忽略了现有版本的numpy(MAC不允许您卸载该版本),并安装了升级版本。
命令:
对我来说很好。
相关问题 更多 >
编程相关推荐