AttributeError:“模块”对象没有属性“ DEVNULL”

时间:2019-11-25 21:52:14

标签: python-2.7 nltk

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'

1 个答案:

答案 0 :(得分:1)

subprocess.devnull是Python 3.3的新功能。

确保使用nltk版本,该版本仍支持Python 2.7。来自their changelog

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