-1

I want to use the PyTLDR. Someone in the issue section on GitHub stated that the module was written in Python 2. Therefore, I set up a Python 2.7 environment for this project. My pip version is 20.3 which should still work for Python 2 modules. While installing the PyTLDR module via pip install pytldr I got the following error message:

[33mDEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.[0m
Processing /home/zyko/.cache/pip/wheels/ba/d8/92/30e242ea7de520ed1eaf44ba37f7e73a2ac1e6b4e305b99e74/PyTLDR-0.1.4-py2-none-any.whl
Processing /home/zyko/.cache/pip/wheels/c7/b1/76/54236c34227a12d32dc9cfe18731976baf8950d8a5aabaea6c/nltk-3.5-py2-none-any.whl
Collecting numpy>=1.8.0
  Using cached numpy-1.16.6-cp27-cp27mu-manylinux1_x86_64.whl (17.0 MB)
Collecting scipy>=0.13.2
  Using cached scipy-1.2.3-cp27-cp27mu-manylinux1_x86_64.whl (24.8 MB)
Processing /home/zyko/.cache/pip/wheels/df/80/48/106e63760ff0dcd3658613d93c1ecf64301b9261172f2c1acf/networkx-2.2-py2.py3-none-any.whl
Processing /home/zyko/.cache/pip/wheels/09/dd/9a/3eff624a1731b5df39e1a946425532b9c1e0330c4e705a629d/goose_extractor-1.0.25-py2-none-any.whl
Collecting scikit-learn>=0.15.2
  Using cached scikit_learn-0.20.4-cp27-cp27mu-manylinux1_x86_64.whl (5.5 MB)
Requirement already satisfied: tqdm in ./venv/lib/python2.7/site-packages (from nltk>=3.0.0->pytldr) (4.61.1)
Requirement already satisfied: click in ./venv/lib/python2.7/site-packages (from nltk>=3.0.0->pytldr) (7.1.2)
Requirement already satisfied: joblib in ./venv/lib/python2.7/site-packages (from nltk>=3.0.0->pytldr) (0.14.1)
Collecting regex
  Using cached regex-2021.4.4.tar.gz (693 kB)
Requirement already satisfied: decorator>=4.3.0 in ./venv/lib/python2.7/site-packages (from networkx>=1.9.1->pytldr) (4.4.2)
Collecting cssselect
  Using cached cssselect-1.1.0-py2.py3-none-any.whl (16 kB)
Processing /home/zyko/.cache/pip/wheels/4b/8e/29/f0d0909969495c5f279c6cba4ceca07db79a0f7bb54f3f087b/jieba-0.42.1-py2-none-any.whl
Collecting beautifulsoup
  Using cached BeautifulSoup-3.2.2-py2-none-any.whl (32 kB)
Collecting lxml
  Using cached lxml-4.6.3-cp27-cp27mu-manylinux1_x86_64.whl (5.5 MB)
Collecting Pillow
  Using cached Pillow-6.2.2-cp27-cp27mu-manylinux1_x86_64.whl (2.1 MB)
Building wheels for collected packages: regex
  Building wheel for regex (setup.py) ... [?25l- error
[31m  ERROR: Command errored out with exit status 1:
   command: /home/zyko/PycharmProjects/PyTLDR/venv/bin/python2.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-9Mtbpc/regex/setup.py'"'"'; __file__='"'"'/tmp/pip-install-9Mtbpc/regex/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-URFXXo
       cwd: /tmp/pip-install-9Mtbpc/regex/
  Complete output (20 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-2.7
  creating build/lib.linux-x86_64-2.7/regex
  copying regex_2/__init__.py -> build/lib.linux-x86_64-2.7/regex
  copying regex_2/regex.py -> build/lib.linux-x86_64-2.7/regex
  copying regex_2/_regex_core.py -> build/lib.linux-x86_64-2.7/regex
  copying regex_2/test_regex.py -> build/lib.linux-x86_64-2.7/regex
  running build_ext
  building 'regex._regex' extension
  creating build/temp.linux-x86_64-2.7
  creating build/temp.linux-x86_64-2.7/regex_2
  x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-QDqKfA/python2.7-2.7.18=. -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:50:10: fatal error: Python.h: No such file or directory
     50 | #include "Python.h"
        |          ^~~~~~~~~~
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
  ----------------------------------------[0m
[31m  ERROR: Failed building wheel for regex[0m
[?25h  Running setup.py clean for regex
Failed to build regex
Installing collected packages: regex, nltk, numpy, scipy, networkx, cssselect, jieba, beautifulsoup, lxml, Pillow, goose-extractor, scikit-learn, pytldr
    Running setup.py install for regex ... [?25l- error
[31m    ERROR: Command errored out with exit status 1:
     command: /home/zyko/PycharmProjects/PyTLDR/venv/bin/python2.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-9Mtbpc/regex/setup.py'"'"'; __file__='"'"'/tmp/pip-install-9Mtbpc/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-pYEqUQ/install-record.txt --single-version-externally-managed --compile --install-headers /home/zyko/PycharmProjects/PyTLDR/venv/include/site/python2.7/regex
         cwd: /tmp/pip-install-9Mtbpc/regex/
    Complete output (20 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-2.7
    creating build/lib.linux-x86_64-2.7/regex
    copying regex_2/__init__.py -> build/lib.linux-x86_64-2.7/regex
    copying regex_2/regex.py -> build/lib.linux-x86_64-2.7/regex
    copying regex_2/_regex_core.py -> build/lib.linux-x86_64-2.7/regex
    copying regex_2/test_regex.py -> build/lib.linux-x86_64-2.7/regex
    running build_ext
    building 'regex._regex' extension
    creating build/temp.linux-x86_64-2.7
    creating build/temp.linux-x86_64-2.7/regex_2
    x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-QDqKfA/python2.7-2.7.18=. -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:50:10: fatal error: Python.h: No such file or directory
       50 | #include "Python.h"
          |          ^~~~~~~~~~
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
    ----------------------------------------[0m
[31mERROR: Command errored out with exit status 1: /home/zyko/PycharmProjects/PyTLDR/venv/bin/python2.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-9Mtbpc/regex/setup.py'"'"'; __file__='"'"'/tmp/pip-install-9Mtbpc/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-pYEqUQ/install-record.txt --single-version-externally-managed --compile --install-headers /home/zyko/PycharmProjects/PyTLDR/venv/include/site/python2.7/regex Check the logs for full command output.[0m
[33mWARNING: You are using pip version 20.3; however, version 20.3.4 is available.
You should consider upgrading via the '/home/zyko/PycharmProjects/PyTLDR/venv/bin/python2.7 -m pip install --upgrade pip' command.[0m
[?25h

It looks like the regex module can not be installed. A manual pip install regex throws the same error message. How can I get regex to work within the old Python 2.7 version and subsequently get the PyTLDR module to work properly?

Zyko
  • 55
  • 1
  • 7
  • https://stackoverflow.com/search?q=%5Bpip%5D+fatal+error%3A+Python.h%3A+No+such+file+or+directory – phd Jun 16 '21 at 16:25

1 Answers1

2

First thing, read the first line of the output: You should not start new projects in python2.

However, the issue is quite straightforward:

    regex_2/_regex.c:50:10: fatal error: Python.h: No such file or directory
       50 | #include "Python.h"
          |          ^~~~~~~~~~

This means that you don't have the headers for python dev installed.

Fix is quite straightforward as well (assuming you're running ubuntu or debian:

sudo apt-get install python-dev
Edo Akse
  • 4,051
  • 2
  • 10
  • 21