在 python 2.7 上安装正则表达式失败,退出状态为 1 [重复]

Posted

技术标签:

【中文标题】在 python 2.7 上安装正则表达式失败,退出状态为 1 [重复]【英文标题】:installing regex on python 2.7 fails with exit status 1 [duplicate] 【发布时间】:2021-09-01 10:53:05 【问题描述】:

我想使用PyTLDR。 GitHub 上issue section 有人表示该模块是用 Python 2 编写的。因此,我为这个项目搭建了 Python 2.7 环境。 我的 pip 版本是 20.3,它仍然适用于 Python 2 模块。 通过pip install pytldr 安装 PyTLDR 模块时,我收到以下错误消息:

[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

似乎无法安装正则表达式模块。手册pip install regex 会引发相同的错误消息。 如何让正则表达式在旧的 Python 2.7 版本中工作,然后让 PyTLDR 模块正常工作?

【问题讨论】:

***.com/… 【参考方案1】:

首先,阅读输出的第一行:You should not start new projects in python2.

但是,问题很简单:

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

这意味着您没有安装 python dev 的标头。

修复也很简单(假设您正在运行ubuntudebian

sudo apt-get install python-dev

【讨论】:

以上是关于在 python 2.7 上安装正则表达式失败,退出状态为 1 [重复]的主要内容,如果未能解决你的问题,请参考以下文章

使用正则表达式使用python 2.7提取电子邮件接收者[重复]

正则表达式入门量词

如何在 Windows 上静默卸载 Python 2.7?

正则表达式仅在 Safari 上失败

Python scikit-image 拉取请求 Travis CI Python 2.7 构建失败

使用 python 和 javascript 的慢正则表达式,但在 go 和 php 中快速失败