词云不适用于pyinstaller

时间:2019-02-15 12:02:23

标签: python pyinstaller word-cloud

我制作了一个显示单词cloud的exe。现在,当我运行它时,它向我显示错误

python 3.6,windows,pyinstaller,wordcloud

sdf = rdf
comment_words = ' '
stopwords = set(STOPWORDS)
for val in sdf.Sentence:
        val = str(val)
    tokens = val.split()
    for i in range(len(tokens)):
        tokens[i] = tokens[i].lower()
    for words in tokens:
        comment_words = comment_words + words + ' '
wordcloud = WordCloud(width = 100, height = 100, 
            background_color ='grey', 
            stopwords = stopwords, 
            min_font_size = 5).generate(comment_words)
plt.figure(figsize = (8, 8), facecolor = None) 
plt.imshow(wordcloud) 
plt.axis("equal") 
plt.title('Word Cloud', bbox={'facecolor':'0.8', 'pad':4})

Exception in Tkinter callback
Traceback (most recent call last):
File "tkinter\__init__.py", line 1702, in __call__
File "TextTrics V1.0.4.py", line 71, in view_stats
File "visual.py", line 52, in show_visuals
File "wordcloud\wordcloud.py", line 605, in generate
File "wordcloud\wordcloud.py", line 587, in generate_from_text
File "wordcloud\wordcloud.py", line 426, in generate_from_frequencies
File "wordcloud\wordcloud.py", line 473, in generate_from_frequencies
File "PIL\ImageFont.py", line 261, in truetype
File "PIL\ImageFont.py", line 144, in __init__
OSError: cannot open resource

1 个答案:

答案 0 :(得分:0)

可能已经晚了,但是我今天遇到了同样的问题,这是我如何解决的问题:

  • 我从wordcloud项目https://github.com/amueller/word_cloud/tree/master/wordcloud的github下载了文件夹wordcloud中包含的所有文件
  • 我将所有这些文件放在文件夹dist/name_of_your_py_file/wordcloud/中,该文件夹在成功运行pyinstaller name_of_your_py_file.py后会自动生成(并且为空)。