【问题标题】:Python pip can't seem to find Python.h despite python-dev installed尽管安装了 python-dev,Python pip 似乎找不到 Python.h
【发布时间】:2014-10-28 12:17:06
【问题描述】:

我目前正在尝试安装 getch,一个简单的 python 包并且遇到了相当多的困难。我最近以一种混乱的方式安装了 pypy(我想在 pypy 的工作中获得 numpy,这是一个相当大的痛苦),所以这可能与我遇到的问题有关。

好的,那我试试跑

sudo pip install getch

我得到了错误...

error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

另外还有一个字符编码错误。

这是人们在没有安装 python-dev 时遇到的错误。不过,我愿意。我试图通过下载包并手动安装来解决这个问题。

sudo python setup.py install

还给了我上面的 gcc 错误。我已经安装了 gcc,并且 x86_64-linux-gnu-gcc 在终端上工作正常。我用 C 语言编写了一个简单的 hello world 程序,其中只包含 Python.h。这也很好。从我的系统中删除 --purging pypy、python 和 python-dev 后,我只重新安装了 python 和 python-dev,但我仍然遇到同样愚蠢的问题。

有人有什么想法吗?

这是我得到的确切错误的粘贴箱。 pastebin.com/mjRdADZx

【问题讨论】:

  • 显示实际错误(来自 gcc)。至少,用 Python.h 显示这一行
  • edit 您的问题并包含来自 pastebin 的信息。该日志表明(我不确定)您正在尝试将 Python 3 扩展编译为 Python 2 扩展。手动下载压缩包并尝试安装它:pip install getch-1.0-python2.tar.gz。不相关:使用 virtualenv 来包含你的实验——如果你破坏了你的系统 python 安装;它可能会使系统无法使用。

标签: python-2.7 pip


【解决方案1】:

您需要手动下载 Python 2 版本并进行安装。 pip 下载的版本是 Python 3 的。

线索是这一行:

Downloading/unpacking getch
  Downloading getch-1.0.tar.gz  # This is the Python 3 package
  Running setup.py egg_info for package getch

Installing collected packages: getch
  Running setup.py install for getch
    building 'getch' extension
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include -I/usr/include -I/usr/include/python2.7 -c getchmodule.c -o build/temp.linux-i686-2.7/getchmodule.o
    getchmodule.c: In function ‘getch_getche’:
    getchmodule.c:36:6: warning: unused variable ‘ok’ [-Wunused-variable]
    getchmodule.c: In function ‘getch_getch’:
    getchmodule.c:43:6: warning: unused variable ‘ok’ [-Wunused-variable]
    getchmodule.c: At top level:
    getchmodule.c:54:15: error: variable ‘getchmodule’ has initializer but incomplete type
    getchmodule.c:55:4: error: ‘PyModuleDef_HEAD_INIT’ undeclared here (not in a function)

Python 2 版本也是 1.0,但是文件名是getch-1.0-python2.tar.gz。可以directly from the index下载。

下载后,解压缩存档,然后从解压缩的目录中python setup.py install

【讨论】:

  • 有没有办法将此需求嵌入到 requirements.txt 文件中,以便在安装时可以愉快地安装到 virtualenv 中?这是 PyPi 库中可以修复的问题吗?我很惊讶 pip 会为错误的 Python 版本拉下一个库。
猜你喜欢
  • 2021-04-20
  • 1970-01-01
  • 2021-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-17
  • 1970-01-01
相关资源
最近更新 更多