TclError:Kaggle中没有显示名称且没有$ DISPLAY环境是可变的

我正在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 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)

我正在执行的错误是:

TclError: no display name and no $DISPLAY environment variable

任何人都可以协助解决该问题吗?

ggtvmtv 回答:TclError:Kaggle中没有显示名称且没有$ DISPLAY环境是可变的

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3001561.html

大家都在问