首页 > 解决方案 > Pandas 未安装在 Ubuntu 中

问题描述

我正在尝试在我的 ubuntu 机器上安装 pandas 库,但没有安装。

pip install pandas
pip3 install pandas

我用过 pip install pandas

Downloading/unpacking pandas
  Downloading pandas-0.25.1.tar.gz (12.6MB): 12.6MB downloaded
  Running setup.py (path:/tmp/pip-build-WzvvgM/pandas/setup.py) egg_info for package pandas
    Traceback (most recent call last):
      File "<string>", line 17, in <module>
      File "/tmp/pip-build-WzvvgM/pandas/setup.py", line 21, in <module>
        import versioneer
      File "versioneer.py", line 1629
        print("Adding sample versioneer config to setup.cfg", file=sys.stderr)
                                                                  ^
    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-WzvvgM/pandas/setup.py", line 21, in <module>

    import versioneer

  File "versioneer.py", line 1629

    print("Adding sample versioneer config to setup.cfg", file=sys.stderr)

                                                              ^

SyntaxError: invalid syntax

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip-build-WzvvgM/pandas
Storing debug log for failure in /home/user508/.pip/pip.log

标签: pythonpandaspip

解决方案


从错误日志中可以清楚地看出,OP 正在使用不受支持的 python 版本。这就是为什么 PIP 尝试使用 file.pandas 安装 pandas 的原因pandas-0.25.1.tar.gz

另一个提示是在这一行,

print("Adding sample versioneer config to setup.cfg", file=sys.stderr)
                                                          ^

这是给

SyntaxError: invalid syntax

此错误清楚地表明 OP 正在使用Python 2.x。上面的 print 语句是 Python 3.x 的,在Python 2.x中使用时会返回错误。例如,请参阅此repl


Pandas库已放弃对 python 版本< 3.5.3的支持。从他们的官方文档中查看支持的版本。它指出,

正式 Python 3.5.3 及更高版本、3.6 和 3.7。

根据他们的 PyPI页面

支持 python 版本< 3.5.3的最新版本是0.24.2

您可以使用以下命令安装它。

pip install pandas==0.24.2

Python 2.7将于2020 年 1 月 1 日结束生命周期。请升级您的 Python,因为 Python 2.7 在该日期之后将不再维护。


推荐阅读