Stack Exchange
Wordcloud error in python
Hi i am trying to generate a wordcliud of my text file searches.txt in Python. Here is my code:
from os import path
from wordcloud import WordCloud
import matplotlib.pyplot as plt

d = path.dirname(__file__)


text = open(path.join(d, 'search.txt')).read()


wordcloud = WordCloud().generate(text)



plt.imshow(wordcloud)
plt.axis("off")

wordcloud = WordCloud(max_font_size=40, relative_scaling=.5).generate(text)
plt.figure()
plt.imshow(wordcloud)
plt.axis("off")
plt.show()

Here is the error::
Traceback (most recent call last):
  File "C:\Python27\wordcloud12.py", line 4, in <module>
    from wordcloud import WordCloud
  File "C:\Python27\lib\site-packages\wordcloud\__init__.py", line 1, in <module>
    from .wordcloud import WordCloud, STOPWORDS, random_color_func, get_single_color_func
  File "C:\Python27\lib\site-packages\wordcloud\wordcloud.py", line 17, in <module>
    from PIL import Image
ImportError: No module named PIL


You should install PIL (or Pillow) first:
pip install pillow

Note that it can be difficult to install PIL/Pillow in a Windows environment. It is easier to download the installer package from:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pillow
then install it using pip, for example:
pip install Pillow-3.2.0-cp27-cp27m-win_amd64.whl


1. Uninstall Following Package
pip uninstall pillow
pip uninstall numpy
pip uninstall wordcloud
pip uninstall matplotlib 
pip uninstall pyparsing
pip uninstall kiwisolver
pip uninstall python-dateutil
pip uninstall cycler
pip uninstall packaging
pip uninstall fonttools
pip uninstall contourpy
pip uninstall six

2. Install wordcloud
pip install wordcloud

