马春杰杰 Exit Reader Mode

Python2安装pandas报错

Python2.7安装Pandas报错:

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 "<string>", line 1, in <module>
      File "/tmp/pip-build-juzWZl/pandas/setup.py", line 333
        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-juzWZl/pandas/
^CTraceback (most recent call last):
  File "/usr/bin/pip2", line 9, in <module>
    load_entry_point('pip==8.1.1', 'console_scripts', 'pip2')()
  File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 217, in main
    return command.main(cmd_args)
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 245, in main
    timeout=min(5, options.timeout)) as session:
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 72, in _build_session
    insecure_hosts=options.trusted_hosts,
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 321, in __init__
    self.headers["User-Agent"] = user_agent()
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 97, in user_agent
    zip(["lib", "version"], platform.libc_ver()),
  File "/usr/lib/python2.7/platform.py", line 169, in libc_ver
    m = _libc_search.search(binary,pos)

原来,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 "<string>", line 1, in <module>
      File "/tmp/pip-build-bDHCSu/numpy/setup.py", line 30, in <module>
        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,然鹅这时即使安装了低版本的numpy,重新安装pandas仍然:

ubuntu@part4:~/bigdisk/$ pip2 install pandas==0.23.0
Collecting pandas==0.23.0
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/76/fa/3bb6b95bf389762c7690ffba2250b6a8a1cbcc321f8cfb864116c98df831/pandas-0.23.0-cp27-cp27mu-manylinux1_x86_64.whl
Collecting numpy>=1.9.0 (from pandas==0.23.0)
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/82/a8/1e0f86ae3f13f7ce260e9f782764c16559917f24382c74edfb52149897de/numpy-1.20.2.zip
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-CB_Dna/numpy/setup.py", line 30, in <module>
        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-CB_Dna/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.

所以,必须一起安装两者才可以,即:

ubuntu@part4:~/bigdisk/$ pip2 install pandas==0.23.0 numpy==1.16.6
Collecting pandas==0.23.0
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/76/fa/3bb6b95bf389762c7690ffba2250b6a8a1cbcc321f8cfb864116c98df831/pandas-0.23.0-cp27-cp27mu-manylinux1_x86_64.whl
Collecting numpy==1.16.6
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/3a/5f/47e578b3ae79e2624e205445ab77a1848acdaa2929a00eeef6b16eaaeb20/numpy-1.16.6-cp27-cp27mu-manylinux1_x86_64.whl
Collecting python-dateutil>=2.5.0 (from pandas==0.23.0)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d4/70/d60450c3dd48ef87586924207ae8907090de0b306af2bce5d134d78615cb/python_dateutil-2.8.1-py2.py3-none-any.whl (227kB)
    100% |████████████████████████████████| 235kB 3.3MB/s 
Collecting pytz>=2011k (from pandas==0.23.0)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/70/94/784178ca5dd892a98f113cdd923372024dc04b8d40abe77ca76b5fb90ca6/pytz-2021.1-py2.py3-none-any.whl (510kB)
    100% |████████████████████████████████| 512kB 906kB/s 
Collecting six>=1.5 (from python-dateutil>=2.5.0->pandas==0.23.0)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ee/ff/48bde5c0f013094d729fe4b0316ba2a24774b3ff1c52d924a8a4cb04078a/six-1.15.0-py2.py3-none-any.whl
Installing collected packages: numpy, six, python-dateutil, pytz, pandas
Successfully installed numpy-1.16.6 pandas-0.23.0 python-dateutil-2.4.2 pytz-2014.10 six-1.10.0
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.

好了,愉快玩耍吧。

本文最后更新于2021年4月8日,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!