Python Tcl错误:Kaggle中没有显示名称和$display环境变量
我正在Kaggle中运行以下代码。语言集是“Python”。尝试对段落执行NLP,并使用下面的代码创建视觉效果Python Tcl错误:Kaggle中没有显示名称和$display环境变量,python,nlp,kaggle,Python,Nlp,Kaggle,我正在Kaggle中运行以下代码。语言集是“Python”。尝试对段落执行NLP,并使用下面的代码创建视觉效果 import matplotlib # Force matplotlib to not use any Xwindows backend. matplotlib.use('Agg') import matplotlib.pyplot import matplotlib.pyplot as plt import pandas as pd import itertools from
import matplotlib
# Force matplotlib to not use any Xwindows backend.
matplotlib.use('Agg')
import matplotlib.pyplot
import matplotlib.pyplot as plt
import pandas as pd
import itertools
from nltk.tokenize import sent_tokenize
from nltk.tokenize import word_tokenize
from nltk.tag import pos_tag
from nltk.tokenize import RegexpTokenizer
from nltk import RegexpParser
document= """The BBC has been testing a new service called SoundIndex, which
lists the top 1,000 artists based on discussions crawled from Bebo,
Last.fm, Google Groups, iTunes, MySpace and YouTube. The top five
bands according to SoundIndex right now are Coldplay, Rihanna, The
Ting Tings, Duffy and Mariah Carey , but the index is refreshed
every six hours. SoundIndex also lets users sort by popular tracks,
search by artist, or create customized charts based on music
preferences or filters by age range, sex or location. Results can
also be limited to just one data source (such as Last.fm).
"""
sentences = sent_tokenize(document)
sentences = [word_tokenize(sent) for sent in sentences]
sentences = [pos_tag(sent) for sent in sentences]
sentence = list(itertools.chain(*sentences))
#grammar = "NP: {<DT>?<JJ>*<NN>}"
grammar = """
NOUN_VERB_NOUN: {<DT>?<VB>*<NN.*>+}
GRUND_NOUN: {<VBG.><NN.*>+}
VN:{<VBN><NN>+}
NOUN_AND_ADJ: {<NN>?<JJ>*<NN.*>+}
{<N.*|JJ.*>*<N.*>} # Nouns and Adjectives, terminated with Nouns
NOUN_PHRASE: {<DT>?<JJ>*<NN>}
ADJ_PHRASE: {}
KEYPHRASE: {<DT>?<JJ>*<NN>}
KEYWORDS: {<NN.*>}
VERB_PHRASE: {<VB.*><NP|PP|CLAUSE>+$} # Chunk verbs and their arguments
CLAUSE: {<NP><VP>}
"""
cp = RegexpParser(grammar)
result = cp.parse(sentence)
#print(result)
result.draw()
for subtree in result.subtrees():
#if subtree.label() == "NOUN_VERB_NOUN":
#print("NOUN_VERB_NOUN: "+str(subtree.leaves()))
print(str(subtree.label())+" "+str(subtree.leaves()))
result.draw()
return(result)
任何人都可以帮助我解决这个问题吗?始终将完整的错误消息(从单词“Traceback”开始)作为文本(而不是屏幕截图)进行讨论(不是评论)。还有其他有用的信息。如果不使用它,为什么要导入
matplotlib
。如果没有定义函数,为什么要使用return
return
仅在自己的函数中使用。至于我result.draw()
不使用matplotlib
来显示带有图像的窗口,但它直接使用tkinter
,您可能无法更改它。在文档中,我发现它使用tkinter.Canvas
来显示它-因此它不是matplotlib
,您无法停止它。只能跳过result.draw()
。也许有功能保存在文件中,并显示从文件,但我不知道它。
TclError: no display name and no $DISPLAY environment variable