【问题标题】:"sre_constants.error: nothing to repeat" error every time trying to install using pip每次尝试使用 pip 安装时都会出现“sre_constants.error: nothing to repeat”错误
【发布时间】:2017-04-04 07:56:54
【问题描述】:

我刚刚在我的 Windows 10 机器上安装了 Python 2.7.5,我还通过 setuptools 安装了 pip。但是,每当我尝试使用 pip 安装某些东西时,例如pip install numpy,我收到此错误消息:

Traceback (most recent call last):
  File "C:\Python27\Scripts\pip-script.py", line 8, in <module>
    load_entry_point('pip==9.0.1', 'console_scripts', 'pip')()
  File "C:\Python27\lib\site-packages\pkg_resources.py", line 318, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "C:\Python27\lib\site-packages\pkg_resources.py", line 2221, in load_entry_point
    return ep.load()
  File "C:\Python27\lib\site-packages\pkg_resources.py", line 1954, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "C:\Python27\lib\site-packages\pip-9.0.1-py2.7.egg\pip\__init__.py", line 26, in <module>
    from pip.utils import get_installed_distributions, get_prog
  File "C:\Python27\lib\site-packages\pip-9.0.1-py2.7.egg\pip\utils\__init__.py", line 27, in <module>
    from pip._vendor import pkg_resources
  File "C:\Python27\lib\site-packages\pip-9.0.1-py2.7.egg\pip\_vendor\pkg_resources\__init__.py", line 73, in <module>
    __import__('pip._vendor.packaging.specifiers')
  File "C:\Python27\lib\site-packages\pip-9.0.1-py2.7.egg\pip\_vendor\packaging\specifiers.py", line 275, in <module>
    class Specifier(_IndividualSpecifier):
  File "C:\Python27\lib\site-packages\pip-9.0.1-py2.7.egg\pip\_vendor\packaging\specifiers.py", line 373, in Specifier
    r"^\s*" + _regex_str + r"\s*$", re.VERBOSE | re.IGNORECASE)
  File "C:\Python27\Lib\re.py", line 190, in compile
    return _compile(pattern, flags)
  File "C:\Python27\Lib\re.py", line 242, in _compile
    raise error, v # invalid expression
sre_constants.error: nothing to repeat

由于我对 Python 还很陌生,所以我不太明白这个错误的含义。有什么解决方法吗?

【问题讨论】:

  • 问题来自用作正则表达式模式的_regex_str。如果它包含|?(? 之类的内容,则会出现问题。如果需要文字字符串匹配,则它必须是 re.escape(_regex_str)

标签: python regex python-2.7 pip


【解决方案1】:

我在使用正则表达式(使用 re.compile() 函数)的库中遇到了类似的问题。我安装了最后一个可用版本 2.7.13(我运行的是 Windows 7)解决了这个问题。 在我拥有 2.7.6 版本之前。我使用 Python 网页中提供的 .msi 安装程序更新了它并安装了新版本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-16
    • 1970-01-01
    • 2019-11-25
    相关资源
    最近更新 更多