导入python的库会导致正则表达式错误吗?

2024-06-13 08:02:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我想了解python的幸运库,也许制作一个基于文本的游戏或一些有用的东西。但无论编写什么代码,每当我导入时,我都会得到一个错误报告

我试过各种代码,包括为其他人编写的完整代码示例,但都是相同的错误

这是一些简单的代码,因为它似乎并不重要

from blessed import Terminal

t = Terminal()

print('Code that does nothing.')

这就是错误

Traceback (most recent call last):
  File "/usr/lib/python3.7/sre_parse.py", line 1015, in parse_template
    this = chr(ESCAPES[this][1])
KeyError: '\\d'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/drew/TBG/test.py", line 3, in <module>
    t = blessed.Terminal()
  File "/usr/lib/python3/dist-packages/blessed/terminal.py", line 226, in __init__
    self.__init__capabilities()
  File "/usr/lib/python3/dist-packages/blessed/terminal.py", line 244, in __init__capabilities
    name, cap, attribute, **kwds)
  File "/usr/lib/python3/dist-packages/blessed/sequences.py", line 134, in build
    pattern = re.sub(r'\d+', _numeric_regex, _outp)
  File "/usr/lib/python3.7/re.py", line 194, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/usr/lib/python3.7/re.py", line 311, in _subx
    template = _compile_repl(template, pattern)
  File "/usr/lib/python3.7/re.py", line 302, in _compile_repl
    return sre_parse.parse_template(repl, pattern)
  File "/usr/lib/python3.7/sre_parse.py", line 1018, in parse_template
    raise s.error('bad escape %s' % this, len(this))
re.error: bad escape \d at position 0

显然,我已经尝试过谷歌搜索,但发现没有人有这个问题,只是其他转义码错误,我不知道如何应用到这个实例中。我尝试通过这些文件跟踪异常,但它们的内容超出了我的级别(而且我没有权限更改它们,这是最好的)

我正在运行Ubuntu14.04,将python 3.7.8作为默认值,并安装了1.17.8

请帮助我确定导致此错误的原因


Tags: 代码inpyreparselibusr错误