7

我在运行 Debian Stretch 的 Windows 10 WSL 上安装 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/
4

5 回答 5

17

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
于 2018-12-12T13:58:12.013 回答
1

运行时出现类似错误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成功了,并且成功安装了正则表达式模块。

于 2020-05-21T12:06:42.200 回答
1

当我在 Alpine 上遇到类似错误时,我登陆了此页面,所以当他遇到类似问题时,我将把这个解决方案留给备用我 :)

apk 添加构建基础--no-cache

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

于 2021-04-02T03:13:38.503 回答
0

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

于 2020-05-08T12:00:42.977 回答
0

我在 Ubuntu 上运行 Python 3.5。我如何能够安装regexPython 包是:

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

背景研究细节:

Python.h我通过使用来确定提供丢失文件的包名称apt-file

# 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,忽略调试(dbg),忽略pypy,从而留下libpython3.5-dev。

于 2020-11-25T22:28:27.743 回答