AttributeError: 'module' object has no attribute 'DEVNULL'

AttributeError: 'module' object has no attribute 'DEVNULL'

from nltk.parse.corenlp import CoreNLPServer
server = CoreNLPServer()
server.start()

当我 运行 上面的代码时,出现以下错误。

Traceback (most recent call last):
  File "server.py", line 30, in <module>
    server.start()
  File "/usr/local/lib/python2.7/dist-packages/nltk/parse/corenlp.py", line 130, in start
    stderr=stderr,
  File "/usr/local/lib/python2.7/dist-packages/nltk/internals.py", line 112, in java
    subprocess_output_dict = {'pipe': subprocess.PIPE, 'stdout': subprocess.STDOUT, 'devnull': subprocess.DEVNULL}
AttributeError: 'module' object has no attribute 'DEVNULL'

subprocess.devnull 是 Python 3.3 中的新增内容。

确保您使用的 nltk 版本仍然支持 Python 2.7。来自 their changelog:

Version 3.5 2019-10-16
* drop support for Python 2