7

I am having issues installing a pip package on Windows 10 WSL running Debian Stretch.

While running sudo pip install invoice2data, with python3-pip installed I run into following errors.

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/
phd
  • 82,685
  • 13
  • 120
  • 165
Sašo
  • 410
  • 1
  • 4
  • 10
  • 1
    Possible duplicate of [fatal error: Python.h: No such file or directory](https://stackoverflow.com/questions/21530577/fatal-error-python-h-no-such-file-or-directory) – phd Dec 12 '18 at 15:32
  • https://stackoverflow.com/search?q=%5Bpip%5D+fatal+error%3A+Python.h%3A+No+such+file+or+directory – phd Dec 12 '18 at 15:32

6 Answers6

17

WSL is unrelated to the issue, this is a fairly standard error.

Ensure the following packages are installed. Install them using apt-get install packagename. The issue this particular time was resolved by installing python-dev.

python3
python3-pip
ipython3
build-essential
python-dev
python3-dev

As a single command:

sudo apt-get install python3 python3-pip ipython3 build-essential python-dev python3-dev
Inigo Flores
  • 4,461
  • 1
  • 15
  • 36
Sašo
  • 410
  • 1
  • 4
  • 10
1

Had a similar error while running 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.

Installing python3-dev didn't work for me, as I already had it installed. However installing build-essential did the trick and the regex module installed successfully.

1

I'm running Python 3.5 on Ubuntu. How I was able to install the regex Python package is:

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

Background research details:

I determined the package name that provides the missing Python.h file by using apt-file to locate it.

# 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

Then made an educated guess as to which package I needed. Ignore Python2, ignore debug (dbg), ignore pypy, thus leaving libpython3.5-dev.

1

I landed on this page when I had a similar error on Alpine so I will leave this solution here for the alternate me when he has a similar issue :)

apk add build-base --no-cache

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

nanacnote
  • 11
  • 1
  • 4
0

restart the bash. I had the same error, but restarting helped

0

If your interpreter is pypy, then install following packages: using sudo apt-get install 'packagename'

pypy3
pypy3-pip
ipypy3
build-essential
pypy-dev
pypy3-dev

Works perfectly for installing nltk and regex

lungsang
  • 133
  • 13