ubuntu下python安装pandas和numpy等依赖库版本不兼容的问题RuntimeWarning: numpy.dtype size changed

习惯了linux下用pip install numpy及pip install pandas命令了。折腾了好久了。

上来先在python3中pip3 install numpy装了numpy,然后再pip3 install pandas就卡住不动了,或者报什么错,然后把numpy卸载了,继续装pandas还是卡住了,好像是找不到相应版本的依赖库。

那就转装python2.7吧,继续pip install pandas,装好了,在pycharm中和命令行交互中导入运行时分别报如下错误:

pycharm下的错误

RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88……

命令行下错误:

ImportError: C extension: No module named missing not built. If you want to import pandas from the source directory, you may need to run 'python

3. 那就下载源码、whl文件试试吧,分别用python2和python3安装,python2可以编源码并安装,只是问题一样,安装whl则报版本不能安装;python3一样的卡住、安装whl不能装。1. 首先想到的当然是百度或谷歌一下,几乎没搜到解决办法。当然我也猜到了是版本不兼容了,所以卸载了numpy、pandas等库,直接pip install pandas,因为发现会自动安装numpy等依赖库,装好了发现还是报一样的问题,继续全删了按照网上的教程来一个个依赖库先装继续装pandas,一样。
2. 难道是pip版本不够?升级下,python -m pip install -U pip。(引用:https://www.cnblogs.com/zhanglin123/p/8526748.html),还是不行。

4. 走投无路了,搜如何查看pandas的依赖库,无果。还试了在虚拟机下安装等手段,或降低版本安装 pip install pandas==0.21.1(最新是0.23.1)。怎么就安装不到合适版本的numpy呢!

5. 无意中,不卸载pandas的时候,执行 pip install pandas,终于出了有用信息

Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: pandas in /usr/local/lib/python2.7/dist-packages (0.21.1)
Requirement already satisfied: pytz>=2011k in /usr/local/lib/python2.7/dist-packages (from pandas) (2018.5)
Requirement already satisfied: python-dateutil in /usr/local/lib/python2.7/dist-packages (from pandas) (2.7.3)
Requirement already satisfied: numpy>=1.9.0 in /usr/local/lib/python2.7/dist-packages (from pandas) (1.15.0)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python2.7/dist-packages/six-1.10.0-py2.7.egg (from python-dateutil->pandas) (1.10.0)

原来这里要求的numpy得是1.9.0以后的版本,而无论是直接装numpy还是通过安装pandas装依赖库都只能装1.15.0的版本,原来pip安装库时并不能寻找到依赖的合适版本,只是执行一样的安装命令而已。

真像大白, pip install numpy==1.9.0安装指定版本,搞定,终于可以正常导入了。

也可以安装 pip install Scikit-learn 了。

经验教训:

    小白真辛苦,望此文能指路。

原文地址:https://www.cnblogs.com/UFO-blogs/p/9389452.html