9

I need to solve a wordcloud problem for a homework assignment.

Unfortunately, I am having a hard time getting wordcloud installed into my environment.

Here is the code I am running:

import os
import matplotlib.pyplot as plt
from wordcloud import WordCloud

I get the following error:

ImportError: No module named 'wordcloud'

Now, I know I need to use the pip install method in my command prompt to get wordcloud into my environment. Even after doing this (and trying several different destinations, including my home directory and the Anaconda3 environment), I continue to get the same error.

What am I doing wrong?

Andrew Smith
  • 539
  • 4
  • 8
  • 15

12 Answers12

16

Try

python -m pip install wordcloud

You probably need numpy and pillow as well.

Harald Nordgren
  • 11,693
  • 6
  • 41
  • 65
11

Try this on Jupyter cell:

!pip install wordcloud
Thiru Balaji G
  • 163
  • 2
  • 10
7

this solution solved my problem which was because of different pythons on my system.

in Jupyter, run:

import sys
print(sys.executable)

to see which python you are using. copy the pass and install the wordcloud with this command from your Jupiter terminal:

path/to/python -m pip install some_package

Which in my case is:

/anaconda3/bin/python -m pip install wordcloud

and import in your code:

from wordcloud import WordCloud

The source i used: can't import

Yasi Klingler
  • 606
  • 6
  • 13
2

Try installing using conda after activating the environment that contains numpy and pillow. Make sure your code is running in that environment.

conda install -c conda-forge wordcloud=1.2.1

Other sources available on anaconda

achille
  • 601
  • 5
  • 13
  • Still not working for me. Is this to be written on the command prompt or in the jupyter notebook? – dekio May 03 '19 at 16:29
2

open anaconda prompt and enter

python -m pip install wordcloud
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
0

I am hoping that you might be using MAC. In that case, check if word cloud got installed in the same place where conda is.

In my case, running it on python3 was working fine but running it on Anaconda was giving an import error.

These are steps that I followed to resolve the issue:

  1. Open the conda terminal from the application. If you are having problems (such as process completed) check whether you are using bash or zsh. Currently conda terminal is supported only on bash. You can change the default shell using the below commands:

Use: chsh -s /bin/bash to change the shell from zsh to bash.

Use: chsh -s /bin/zsh to revert back to zsh later.

  1. Once changed to bash, install word cloud for anaconda using the below command:

conda install -c conda-forge wordcloud

Voila! Your imports should work now, just as mine did.

Radioactive
  • 611
  • 1
  • 11
  • 20
  • "check whether you are using bash or zsh" how do I do this? – dekio May 03 '19 at 14:19
  • You could do this in multiple ways - echo $0, echo $SHELL ( You can refer to the answer - https://stackoverflow.com/questions/9910966/how-to-tell-if-its-using-zsh-or-bash) – Radioactive May 06 '19 at 17:41
0

I had the same issue, had to make a new conda environment and then installed it. (https://conda.io/docs/user-guide/getting-started.html)

"1.Create a new environment and install a package in it. We will name the environment snowflakes and install the package wordcloud. At the Anaconda Prompt or in your Terminal window, type the following:"

conda create --name snowflakes wordcloud
Community
  • 1
  • 1
Max
  • 1
  • 4
0

to install wordcloud - execute "pip install wordcloud" from Anaconda prompt (not cmd)

Gth lala
  • 322
  • 2
  • 4
0

After installing wordcloud using pip python -m pip install wordcloud, its working fine in jupyter Notebook.

pip install wordcloud

sourav
  • 41
  • 1
  • 1
  • 3
0

open anaconda prompt and enter

pip install wordcloud

Then go to jupyter and write

from wordcloud import WordCloud
Dharman
  • 30,962
  • 25
  • 85
  • 135
0

As you are using Jupyter Notebook. Try using following these commands in Anaconda prompt. It will work fine.

conda install -c conda-forge wordcloud
conda install -c conda-forge/label/gcc7 wordcloud
conda install -c conda-forge/label/cf201901 wordcloud
conda install -c conda-forge/label/cf202003 wordcloud
-1

Before install libpython3-dev

$ sudo apt-get install libpython3-dev
$ sudo pip install wordcloud
Wender
  • 991
  • 15
  • 24