-1

I can't import pytagcloud in jupyter notebook. How do I solve this problem? I searched some tutorials and also installed other packages required but still doesn't work?

Do you have any suggestion?

Here is my code. Thanks.

import pytagcloud as pytagcloud

import codecs
from bs4 import BeautifulSoup
from konlpy.tag import Twitter
# utf-16 인코딩으로 파일을 열고 글자를 출력하기 --- (※1)
samsung = codecs.open("samsung.txt", encoding="utf-8")
line = samsung.readlines()
twitter = Twitter()
word_dic = {}
for line in line:
     malist = twitter.pos(line)
     for word in malist:
         if word[1] == "Noun": #  명사 확인하기 --- (※3)
            if not (word[0] in word_dic):
                word_dic[word[0]] = 0
            word_dic[word[0]] += 1 # 카운트하기
# 많이 사용된 명사 출력하기 --- (※4)
keys = sorted(word_dic.items(), key=lambda x:x[1], reverse=True)
for word, count in keys[:40]:
     print("{0}({1}) ".format(word, count), end="")
print()

keys

import pytagcloud
taglist = pytagcloud.make_tags(keys, maxsize = 80)
taglist

pytagcloud.create_tag_image(taglist, 'wordcolud.jpg', size = (900,600), fontname = 'Nobile', rectangular = False)

%matplotlib inline
import matplotlib.pyplot as plt
from wordcloud import WordCloud as wordcloud

wordcloud = WordCloud(stopwords = stopwords)
wordcloud = wordcloud.generate_from_keys(keys)

wordcloud = WordCloud().generate(keys)

draw_wordcloud_from_rss(keys)

cmd:pytagcloud

cmd:pygame

cmd:simplejson

jupyter notebook: pytagcloud

jnashm
  • 33
  • 1
  • 7
  • Welcome to SO. Please post relevant code, error messages and printouts not as images but rather inline in your question. Thanks! – petezurich Dec 06 '18 at 07:16
  • How are you running jupyter? Is it the same python installation as pip? If there are multiple python installations you may be installing the libraries in the wrong one. See [ask], and how to create a [mcve]. – Peter Wood Dec 06 '18 at 07:17
  • Yes, thank you for reminding me:) I edited my post with code. – jnashm Dec 06 '18 at 10:21
  • First, I open Anaconda prompt and then I type "jupyter notebook" on it. – jnashm Dec 06 '18 at 10:23

1 Answers1

0

I asked one of my colleagues and she gave the answer!

So the problem was simple. I installed all those libraries in 'cmd'

but I had to install them in "Anaconda prompt".

So, if you have same problem as mine, try this.

# Anaconda prompt

pip install pygame
pip install -U pytagcloud
pip install simplejson
jupyter notebook.

# Import.

I succeeded to import pygame, pytagcloud and simplejson libraries. Yet, I have still errors in my code of the post above and there is more libraries to install(konply..etc). error is everywhere!

Anyway, I hope this helps someone.

jnashm
  • 33
  • 1
  • 7