ImportError: cannot import name 'escape' from 'cgi'

ImportError: cannot import name 'escape' from 'cgi'

当我尝试在 pycharm 中使用以下代码时收到错误消息 "ImportError: cannot import name 'escape' from 'cgi'":

import nltk 
parser = nltk.ChartParser(grammar, trace=0)

for tree in parser.parse(sent):
    print(tree)
    tree.pretty_print(unicodelines=True)

我应该怎么做才能纠正它?

cgi.escape() 已在 python 3.8 中删除。引用自 here,

parse_qs, parse_qsl, and escape are removed from the cgi module. They are deprecated in Python 3.2 or older. They should be imported from the urllib.parse and html modules instead.

由于您正在导入第三方模块,请尝试使用较低的 python 版本。

我已将 supervisor 软件包版本更新为: supervisor==4.1.0

https://pypi.org/project/supervisor/4.1.0/

[修复了因删除 cgi.escape() 而导致的 Python 3.8 兼容性问题。 Mattia Procopio 的补丁。]

问题已解决。