Python2.7 pip安装pandas报错


先使用命令解决:pip2 install pandas==0.23.0 numpy==1.16.6

原因如下:

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-juzWZl/pandas/
ubuntu@part4:~/bigdisk/part4 $ pip2 install pandas
Collecting pandas
 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/8a/6f/7fcef020b5b305862cacf376183eaa0f907f2fa42f0b687b2a9a2c6cda4d/pandas-1.2.3.tar.gz (5.5MB)
 100% |████████████████████████████████| 5.5MB 161kB/s
 Complete output from command python setup.py egg_info:
 Traceback (most recent call last):
 File "", line 1, in
 File "/tmp/pip-build-juzWZl/pandas/setup.py", line 333
 f"{extension}-source file '{sourcefile}' not found.\n"
 ^
 SyntaxError: invalid syntax

原来,pandas自从0.23.0之后就不支持Python2了,所以需要更换版本,但是这时可能会出现第二个问题:

ubuntu@part4:~/bigdisk/$ pip2 install pandas==0.23.0
Collecting pandas==0.23.0
 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/76/fa/3bb6b95bf389762c7690ffba2250b6a8a1cbcc321f8cfb864116c98df831/pandas-0.23.0-cp27-cp27mu-manylinux1_x86_64.whl (11.8MB)
 100% |████████████████████████████████| 11.8MB 94kB/s
Collecting numpy>=1.9.0 (from pandas==0.23.0)
 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/82/a8/1e0f86ae3f13f7ce260e9f782764c16559917f24382c74edfb52149897de/numpy-1.20.2.zip (7.8MB)
 100% |████████████████████████████████| 7.8MB 133kB/s
 Complete output from command python setup.py egg_info:
 Traceback (most recent call last):
 File "", line 1, in
 File "/tmp/pip-build-bDHCSu/numpy/setup.py", line 30, in
 raise RuntimeError("Python version >= 3.7 required.")
 RuntimeError: Python version >= 3.7 required.
 ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-bDHCSu/numpy/
You are using pip version 8.1.1, however version 21.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.


原来在安装pandas的时候还会自动安装numpy,但是最新版的numpy也不支持python2了,所以我们需要安装低版本的numpy,比如1.16.6,应为两个版本有依赖,所以,需要一起安装才OK,即:

pip2 install pandas==0.23.0 numpy==1.16.6


原文链接:https://codingdict.com/