Python2.7安装Pandas
报错:
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-juzWZl/pandas/
在ubuntu16.04 Python2.7环境下安装pandas,输入指令pip2 install pandas
,结果如下:
chen@chen-QiTianM415-D070:~/Downloads$ pip2 install pandas
Collecting pandas
Using cached https://files.pythonhosted.org/packages/5a/ac/b3b9aa2318de52e40c26ae7b9ce6d4e9d1bcdaf5da0899a691642117cf60/pandas-1.4.2.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-lA4vap/pandas/setup.py", line 250
f"{extension}-source file '{sourcefile}' not found.\n"
^
SyntaxError: invalid syntax
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-lA4vap/pandas/
原因是pandas自从0.23.0之后就不支持Python2了,所以需要更换版本,输入pip2 install pandas==0.23.0
,但是这时可能会出现第二个问题,提示numpy出现了同样的问题.
chen@chen-QiTianM415-D070:~/Downloads$ pip2 install pandas==0.23.0
Collecting pandas==0.23.0
Downloading https://files.pythonhosted.org/packages/76/fa/3bb6b95bf389762c7690ffba2250b6a8a1cbcc321f8cfb864116c98df831/pandas-0.23.0-cp27-cp27mu-manylinux1_x86_64.whl (11.8MB)
100% |████████████████████████████████| 11.8MB 51kB/s
Collecting numpy>=1.9.0 (from pandas==0.23.0)
Downloading https://files.pythonhosted.org/packages/64/4a/b008d1f8a7b9f5206ecf70a53f84e654707e7616a771d84c05151a4713e9/numpy-1.22.3.zip (11.5MB)
100% |████████████████████████████████| 11.5MB 26kB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-MobKDs/numpy/setup.py", line 59
raise RuntimeError(f'Cannot parse version {FULLVERSION}')
^
SyntaxError: invalid syntax
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-MobKDs/numpy/
原来在安装pandas的时候还会自动安装numpy,但是最新版的numpy也不支持python2了,所以我们需要安装低版本的numpy,比如1.16.6.注意,这里必须把numpy和pandas同时安装.
pip2 install pandas==0.23.0 numpy==1.16.6
chen@chen-QiTianM415-D070:~/Downloads$ pip2 install pandas==0.23.0 numpy==1.16.6
Collecting pandas==0.23.0
Using cached https://files.pythonhosted.org/packages/76/fa/3bb6b95bf389762c7690ffba2250b6a8a1cbcc321f8cfb864116c98df831/pandas-0.23.0-cp27-cp27mu-manylinux1_x86_64.whl
Collecting numpy==1.16.6
Downloading https://files.pythonhosted.org/packages/3a/5f/47e578b3ae79e2624e205445ab77a1848acdaa2929a00eeef6b16eaaeb20/numpy-1.16.6-cp27-cp27mu-manylinux1_x86_64.whl (17.0MB)
100% |████████████████████████████████| 17.0MB 17kB/s
Collecting python-dateutil>=2.5.0 (from pandas==0.23.0)
Downloading https://files.pythonhosted.org/packages/36/7a/87837f39d0296e723bb9b62bbb257d0355c7f6128853c78955f57342a56d/python_dateutil-2.8.2-py2.py3-none-any.whl (247kB)
100% |████████████████████████████████| 256kB 50kB/s
Collecting pytz>=2011k (from pandas==0.23.0)
Downloading https://files.pythonhosted.org/packages/60/2e/dec1cc18c51b8df33c7c4d0a321b084cf38e1733b98f9d15018880fb4970/pytz-2022.1-py2.py3-none-any.whl (503kB)
100% |████████████████████████████████| 512kB 77kB/s
Collecting six>=1.5 (from python-dateutil>=2.5.0->pandas==0.23.0)
Downloading https://files.pythonhosted.org/packages/d9/5a/e7c31adbe875f2abbb91bd84cf2dc52d792b5a01506781dbcf25c91daf11/six-1.16.0-py2.py3-none-any.whl
Installing collected packages: numpy, six, python-dateutil, pytz, pandas
Successfully installed numpy-1.11.0 pandas python-dateutil-2.4.2 pytz-2014.10 six-1.10.0
成功在Python2.7环境下安装好pandas.