Python 使用 Jupyter Notebook 安装 wordcloud
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41792471/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Installing wordcloud using Jupyter Notebook
提问by Andrew Smith
I need to solve a wordcloud problem for a homework assignment.
我需要解决家庭作业的 wordcloud 问题。
Unfortunately, I am having a hard time getting wordcloud installed into my environment.
不幸的是,我很难将 wordcloud 安装到我的环境中。
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'
导入错误:没有名为“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.
现在,我知道我需要在命令提示符中使用 pip install 方法才能将 wordcloud 引入我的环境。即使在这样做之后(并尝试了几个不同的目的地,包括我的主目录和 Anaconda3 环境),我仍然会遇到同样的错误。
What am I doing wrong?
我究竟做错了什么?
回答by Harald Nordgren
Try
尝试
python -m pip install wordcloud
You probably need numpy
and pillow
as well.
你可能需要numpy
,pillow
以及。
回答by Yasi Eslahi
this solution solved my problem which was because of different pythons on my system.
这个解决方案解决了我的问题,这是因为我的系统上有不同的 python。
in Jupyter, run:
在 Jupyter 中,运行:
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:
查看您使用的是哪个python。从您的 Jupiter 终端复制通行证并使用以下命令安装 wordcloud:
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
我使用的来源: 无法导入
回答by prashanthjoshua
open anaconda prompt and enter
打开 anaconda prompt 并输入
python -m pip install wordcloud
回答by Max
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 环境然后安装它。( https://conda.io/docs/user-guide/getting-started.html)
“1.创建一个新环境并在其中安装一个包。我们将环境命名为snowflakes并安装包wordcloud。在Anaconda Prompt或您的终端窗口中,键入以下内容:”
conda create --name snowflakes wordcloud
回答by Gth lala
to install wordcloud - execute "pip install wordcloud" from Anaconda prompt (not cmd)
安装 wordcloud - 从 Anaconda 提示符(不是 cmd)执行“pip install wordcloud”
回答by sourav
After installing wordcloud using pip python -m pip install wordcloud
, its working fine in jupyter Notebook.
使用 pip 安装 wordcloud 后python -m pip install wordcloud
,它在 jupyter Notebook 中工作正常。
回答by Sravani Tholam
open anaconda prompt and enter
打开 anaconda prompt 并输入
pip install wordcloud
Then go to jupyter and write
然后去jupyter写
from wordcloud import WordCloud
回答by achille
Try installing using conda after activating the environment that contains numpy and pillow. Make sure your code is running in that environment.
激活包含 numpy 和枕头的环境后,尝试使用 conda 进行安装。确保您的代码在该环境中运行。
conda install -c conda-forge wordcloud=1.2.1
Other sources available on anaconda
anaconda 上可用的其他资源
回答by Radioactive
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.
我希望您可能正在使用 MAC。在这种情况下,请检查 word cloud 是否安装在 conda 所在的同一位置。
In my case, running it on python3 was working fine but running it on Anaconda was giving an import error.
就我而言,在 python3 上运行它工作正常,但在 Anaconda 上运行它会出现导入错误。
These are steps that I followed to resolve the issue:
这些是我为解决问题而遵循的步骤:
- Open the condaterminal 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:
- 从应用程序打开conda终端。如果您遇到问题(例如进程已完成),请检查您使用的是 bash 还是 zsh。目前仅 bash 支持 conda 终端。您可以使用以下命令更改默认 shell:
Use: chsh -s /bin/bash to change the shell from zsh to bash.
使用: chsh -s /bin/bash 将 shell 从 zsh 更改为 bash。
Use: chsh -s /bin/zsh to revert back to zsh later.
使用: chsh -s /bin/zsh 稍后恢复到 zsh。
- Once changed to bash, install word cloud for anaconda using the below command:
- 更改为 bash 后,使用以下命令为 anaconda 安装 word cloud:
conda install -c conda-forge wordcloud
conda install -c conda-forge wordcloud
Voila! Your imports should work now, just as mine did.
瞧!你的导入现在应该可以工作了,就像我的一样。
回答by Wender
Before install libpython3-dev
安装libpython3-dev之前
$ sudo apt-get install libpython3-dev
$ sudo pip install wordcloud