Как я могу решить "Невозможно найти" C: \ Users \ user \ nltk_data "при добавлении двоичных файлов и файлов данных"? - PullRequest
0 голосов
/ 04 марта 2020

Я пытался создать .py для исполняемого файла, но у меня проблема, пожалуйста, помогите

Вот мой код:

import nltk
import numpy as np
from wordcloud import WordCloud, STOPWORDS
import matplotlib.pylab as plt
from konlpy.tag import Twitter
from PIL import Image
import PIL
import random
from tkinter import *
from tkinter.filedialog import *

root = Tk()
root.title("WordCloud")
root.geometry("640x400+100+100")
root.resizable(False, False)

name = ""
background = None
stopwords = None

def grey_color(word, font_size, position, orientation, random_state=None, **kwargs):
    return 'hsl(0, 0%%, %d%%)' % random.randint(80, 100)

def get_text_path():
    global name
    name = askopenfilename()
    print(name)

def get_img_path():
    global background, stopwords
    file = askopenfilename()
    background = np.array(PIL.Image.open(file))
    print(background)

def make_wordcould():
    global background, stopwords
    text = open(name, encoding='utf-8').read()
    wc = WordCloud(background_color='white', margin=5, mask=background,
                   max_words=2000, stopwords=stopwords, random_state=1).generate(text)
    default_colors = wc.to_array()
    plt.figure(figsize=(10, 10))
    plt.imshow(wc, interpolation='bilinear')
    # plt.imshow(wc.recolor(color_func=grey_color, random_state=3), interpolation='bilinear')
    plt.axis('off')
    plt.show()

def make_korean():
    global background, stopwords
    text = open(name, encoding='utf-8').read()
    t = Twitter()
    token = t.nouns(text)
    count_voca = nltk.Text(token, name="vocab counting")
    count_voca.vocab()
    voca = count_voca.vocab().most_common(150)
    font ="/usr/share/fonts/NanumFont/NanumGothicBold.ttf"
    wordcloud = WordCloud(font_path=font, max_words=2000,
                          relative_scaling=0.2,
                          background_color="white", mask=background).generate_from_frequencies(dict(voca))
    plt.figure(figsize=(12, 12))
    plt.imshow(wordcloud, interpolation='bilinear')
    # plt.imshow(wordcloud.recolor(color_func=grey_color, random_state=3), interpolation='bilinear')
    plt.axis('off')
    plt.show()

Bt1 = Button(root, text = "Upload Text File", command = get_text_path, font="/usr/share/fonts/NanumFont/NanumGothicBold.ttf")
Bt1.place(x = 150, y = 60, width = 160, height = 50)

Bt2 = Button(root, text = "English Word Cloud", command = make_wordcould, font="/usr/share/fonts/NanumFont/NanumGothicBold.ttf")
Bt2.place(x = 150, y = 120, width = 160, height = 50)

Bt3 = Button(root, text = "Korean Word Cloud", command = make_korean, font="/usr/share/fonts/NanumFont/NanumGothicBold.ttf")
Bt3.place(x = 320, y = 120, width = 170, height = 50)

Bt4 = Button(root, text = "WordCloud\n Image Upload", command = get_img_path, font="/usr/share/fonts/NanumFont/NanumGothicBold.ttf")
Bt4.place(x = 320, y =60, width=170, height = 50)

LB1 = Label(root, text = "* Rectangle is Default Set\n")
LB1.config(font=("/usr/share/fonts/NanumFont/NanumGothicBold.ttf", 10))
LB1.place(x = 160, y = 200, width = 330, height = 50)

LB2 = Label(root, text = "WORD CLOUD Program")
LB2.config(font=("/usr/share/fonts/NanumFont/NanumGothicBold.ttf", 20))
LB2.place(x = 30, y = 10, width = 600, height = 30)

print("="*30, "Button and Label Complete\n", "="*30)
root.mainloop()

21200 ИНФОРМАЦИЯ: Бэкэнд Matplotlib "svg": добавлено 21601 ИНФОРМАЦИЯ: бэкэнд Matplotlib "template": добавлено 21790 ИНФОРМАЦИЯ: крюк модуля загрузки "hook-matplotlib.py" ... 22062 ИНФОРМАЦИЯ: крюк модуля загрузки "hook-nltk.py" ... Невозможно найти "C : \ Users \ user \ nltk_data "при добавлении двоичных файлов и файлов данных.

...