@python的pandas库安装总是失败TOC
- *一、问题解决过程
在python2环境运行脚本时,提示ImportError: No module named pandas。于是发现的确没有pandas模块,于是就去安装pandas模块。但是安装pandas时总是失败。
Downloading/unpacking pandas
Downloading pandas-1.3.4.tar.gz (4.7MB): 4.7MB downloaded
Running setup.py (path:/tmp/pip_build_root/pandas/setup.py) egg_info for package pandas
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/tmp/pip_build_root/pandas/setup.py", line 249
f"{extension}-source file '{sourcefile}' not found.\n"
^
SyntaxError: invalid syntax
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/tmp/pip_build_root/pandas/setup.py", line 249
f"{extension}-source file '{sourcefile}' not found.\n"
^
SyntaxError: invalid syntax
在网上查看,原因可能是pandas工具对python2工具的支持情况。pandas工具在后期版本不再支持python2。于是在pip2 install时指定版本进行安装,还是一样的问题。
pip2 install pandas==0.24.2 -i 源地址
numpy能成功安装:
pip2 install numpy==1.16.6 -i 源地址
即使同时按照pandas和numpy,问题依然存在:
pip2 install pandas=0.24.2 numpy==1.16.6 -i 源地址
后来发现,pip的版本过低,如下为1.5.4版本,于是升级pip版本:
-bash-4.2$ pip --version
pip 1.5.4 from /usr/lib/python2.7/site-packages/pip-1.5.4-py2.7.egg (python 2.7)
-bash-4.2$ pip2 --version
pip 1.5.4 from /usr/lib/python2.7/site-packages/pip-1.5.4-py2.7.egg (python 2.7)
-bash-4.2$
在https://pypi.org/project/pip/19.0.3/#files/pip-19.0.3.tar.gz 下载到pip-19.0.3.tar.gz后,在服务器 上随意找一个目录(选择的包存放目录没有强制要求)存放并解压、安装:
bash-4.2#tar -zxvf pip-19.0.3.tar.gz
bash-4.2#cd pip-19.0.3
bash-4.2#python setup.py install
安装成功;安装成功后,安装pandas的0.24.2版本终于成功啦!
bash-4.2# pip install pandas==0.24.2 -i 源地址
但是,此时问题又来了,报ImportError: Missing required dependencies [‘numpy’]错误:
import pandas as pd
File "/usr/lib64/python2.7/site-packages/pandas/__init__.py", line 19, in <module>
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
pip list查看,已有numpy:“numpy 1.16.4”,版本号是1.16.4。
bash-4.2# pip list | grep pandas
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
pandas 0.24.2
bash-4.2# pip list | grep numpy
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
numpy 1.16.4
bash-4.2# pip list | grep setuptools
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
setuptools 0.8b2
bash-4.2#
即在安装 Pandas 0.24.2模块后,导入模块时提示 “Missing required dependencies{0}”.format(missing_dependencies)) ImportError: Missingrequired dependencies [‘numpy’] ,虽然系统已安装了numpy(https://blog.csdn.net/zf_14159265358979/article/details/84639899)。
于是先卸载pandas模块、再卸载numpy模块,然后一起安装,问题仍然在。 于是在pip uninstall numpy后,去/usr/lib64/python2.7/site-packages/目录下查看,numpy相关的目录是否已删除干净。发现,的确没有删除干净,还有一个numpy目录。安装numpy后,在/usr/lib64/python2.7/site-packages/目录下会有2个numpy相关的目录,如下所示。卸载numpy后,只有numpy-1.16.2.dist-info目录消失,numpy目录仍然在。于是将numpy目录删除(建议最好mv到另外一个目录,以防万一该方法不凑效,删除对系统有影响),然后将pandas模块也pip uninstall卸载。
drwxr-xr-x 17 root root 4096 10月 22 13:59 numpy
drwxr-xr-x 2 root root 111 10月 22 13:59 numpy-1.16.2.dist-info
然后同时一起安装pandas和numpy模块,均成功安装;直接脚本,问题得到解决,不再报ImportError: Missing required dependencies [‘numpy’]错误了。
2.解决方法总结
(1)pandas模块与numpy模块息息相关; (2)pandas模块与numpy模块的高版本不再支持python2版本;故在python2环境如果需要使用pandas模块,需要注意其版本;同时也要关注numpy的版本号。 (3)pip的版本也很重要,版本如果过低,pandas模块也会安装失败。我在使用过程中就是因为pip是0.5.4版本过低,导致pandas安装失败,将版本升级到19.0.3版本,pandas安装成功,问题得到解决。 (3)import pandas as pd报 “Missing required dependencies {0}”.format(missing_dependencies)) ImportError: Missing required dependencies [‘numpy’]错误时,可能是存在多个numpy所致。此时可以pip uninstall卸载numpy模块,然后查看/usr/lib64/python2.7/site-packages/目录下numpy相关目录是否已被删除干净,如果没有,则将numpy相关目录删除,再重新安装numpy模块就可以成功安装,该问题会得到解决。 pandas 0.24.2 numpy 1.16.2 pip 19.0.3
3. 参考资料 在问题解决过程中,查阅过如下博文,谢谢知识分享: https://www.machunjie.com/trouble/code_error/904.html https://blog.csdn.net/Com_ma/article/details/78025350 https://blog.csdn.net/zf_14159265358979/article/details/84639899 https://www.jiqizhixin.com/articles/2017-11-18-2 https://blog.csdn.net/qq_30500113/article/details/96880835 https://www.cnblogs.com/shandian333/p/14630097.html
|