"Failed building wheel for regex" 安装 pip 包时

"Failed building wheel for regex" while installing pip package

我在 Windows 10 WSL 运行ning Debian Stretch 上安装 pip 包时遇到问题。

当 运行 宁 sudo pip install invoice2data 时,安装 python3-pip 我 运行 出现以下错误。

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

----------------------------------------
Failed building wheel for regex
Running setup.py clean for regex
Failed to build regex

x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-2.7.13=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c regex_2/_regex.c -o build/temp.linux-x86_64-2.7/regex_2/_regex.o
regex_2/_regex.c:46:20: fatal error: Python.h: No such file or directory
 #include "Python.h"
                    ^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1


----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, okenize;__file__='/tmp/pip-install-D9zG6P/regex/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-0dvlsB/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-D9zG6P/regex/

WSL 与问题无关,这是一个相当标准的错误。

确保安装了以下软件包。使用 apt-get install packagename 安装它们。这个特定时间的问题已通过安装 python-dev.

得到解决
python3
python3-pip
ipython3
build-essential
python-dev
python3-dev

作为单个命令:

sudo apt-get install python3 python3-pip ipython3 build-essential python-dev python3-dev

重新启动 bash。我有同样的错误,但重新启动有帮助

在 运行 pip3 install pyinquirer

时出现了类似的错误
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-a7ojseph/regex/setup.py'"'"'; __file__='"'"'/tmp/pip-install-a7ojseph/regex/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-bodowot9/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.7/regex Check the logs for full command output.

安装 python3-dev 对我不起作用,因为我已经安装了它。但是安装 build-essential 成功了,正则表达式模块安装成功。

我 运行 Python 3.5 Ubuntu。我是如何安装 regex Python 软件包的:

$ sudo apt-get install libpython3.5-dev
$ pip3 install regex --no-use-wheel

背景研究详情:

我通过使用 apt-file 找到提供丢失的 Python.h 文件的软件包名称。

# install the apt-file package in case you don't have it
$ sudo apt-get install apt-file

# populate/refresh the local apt-file package data
$ sudo apt-file update

# search for /Python.h.  Since it's a C header file,
# I also grep for /include to limit the results.
$ sudo apt-file search /Python.h | grep /include
libpython2.7-dbg: /usr/include/python2.7_d/Python.h
libpython2.7-dev: /usr/include/python2.7/Python.h
libpython3.5-dbg: /usr/include/python3.5dm/Python.h
libpython3.5-dev: /usr/include/python3.5m/Python.h
pypy-dev: /usr/lib/pypy/include/Python.h

然后对我需要哪个软件包进行了有根据的猜测。忽略Python2,忽略debug(dbg),忽略pypy,从而留下libpython3.5-dev.

当我在 Alpine 上遇到类似的错误时,我进入了这个页面,所以当他有类似的问题时,我将把这个解决方案留在这里供替代我使用:)

apk 添加 build-base --no-cache

https://wiki.alpinelinux.org/wiki/GCC