TypeError: 'module' object is not callable in Spacy Python

TypeError: 'module' object is not callable in Spacy Python

我想使用 Spacy 打印 Parse Tree。但是下面的代码给出了错误

en_nlp = spacy.language('English') TypeError: 'module' object is not callable

错误在此 en_nlp = spacy.loads('en') 行。我试图通过导入 from spacy.en import English 摆脱 en_nlp = spacy.language(English) 但它仍然无法正常工作。有人可以帮忙吗?

代码:

import spacy
from nltk import Tree

en_nlp = spacy.loads('en')

doc = en_nlp("The quick brown fox jumps over the lazy dog.")

def to_nltk_tree(node):
    if node.n_lefts + node.n_rights > 0:
        return Tree(node.orth_, [to_nltk_tree(child) for child in node.children])
    else:
        return node.orth_


[to_nltk_tree(sent.root).pretty_print() for sent in doc.sents]

Is it spacy.load('en') or spacy.loads('en') ?

官方文档https://spacy.io/docs/说: spacy.load('en')。 可能是这个问题。