Python jupyter ModuleNotFoundError:没有名为 matplotlib 的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42321784/
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
jupyter ModuleNotFoundError: No module named matplotlib
提问by Bullfraud
I am currently trying to work basic python - jupyter projects.
我目前正在尝试使用基本的 python - jupyter 项目。
I am stuck on following error during matplotlib:
我在 matplotlib 期间遇到以下错误:
ModuleNotFoundError: No module named 'matplotlib'
ModuleNotFoundError: 没有名为“ matplotlib”的模块
I tried to update, reinstall matplotlib aswell in conda and in pip but it still not working.
我尝试在 conda 和 pip 中更新、重新安装 matplotlib,但它仍然无法正常工作。
happy over every constructive feedback
对每一个建设性的反馈感到高兴
回答by Frédéric
In a Notebook's cell type and execute the code:
在 Notebook 的单元格类型中并执行代码:
import sys
!{sys.executable} -m pip install --user matplotlib
and reload the kernel
并重新加载内核
(src: http://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/)
(源代码:http: //jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/)
回答by Shahriar Miraj
open terminal and change the directory to Scripts folder where python installed. Then type the following command and hit enter
打开终端并将目录更改为安装python的Scripts文件夹。然后输入以下命令并回车
pip install matplotlib
Hope this will solve the issue.
希望这能解决问题。
回答by bhaskarc
I was facing the exact issue. Turns out it was using the system Python version despite me having activated my virtual environment.
我正面临着确切的问题。事实证明,尽管我已经激活了我的虚拟环境,但它使用的是系统 Python 版本。
This is what eventually worked.
这就是最终奏效的方法。
If you are using a virtual environment which has a name say myvenv
, first activate it using command:
如果您使用的是名称为 say 的虚拟环境myvenv
,请首先使用以下命令激活它:
source activate myenv
Then install module ipykernel
using the command:
然后ipykernel
使用以下命令安装模块:
pip install ipykernel
Finally run (change myenv in code below to the name of your environment):
最后运行(将下面代码中的 myenv 更改为您的环境名称):
ipykernel install --user --name myenv --display-name "Python (myenv)"
Now restart the notebook and it should pick up the Python version on your virtual environment.
现在重新启动笔记本,它应该会在您的虚拟环境中选择 Python 版本。
回答by bboucher
Having the same issue, installing matplotlib beforeto create the virtualenv solved it for me. Then I created the virtual environment and installed matplotlib on it before to start jupyter notebook.
遇到同样的问题,在创建 virtualenv之前安装 matplotlib为我解决了这个问题。然后我创建了虚拟环境并在启动 jupyter notebook 之前在其上安装了 matplotlib。
回答by Siddharth Sharma
The issue with me was that jupyter was taking python3 for me, you can always check the version of python jupyter is running on by looking on the top right corner (attached screenshot).
我的问题是 jupyter 正在为我使用 python3,您可以随时通过查看右上角(附加屏幕截图)来检查 python jupyter 正在运行的版本。
When I was doing pip install it was installing the dependencies for python 2.7 which is installed on mac by default. It got solved by doing:
当我进行 pip install 时,它正在安装默认安装在 mac 上的 python 2.7 的依赖项。它通过执行以下操作得到解决:
> pip3 install matplotlib
回答by Biranchi
Check the python version:
检查python版本:
$python --version
or
或者
$python3 --version
Try installing "matplotlib" using sudo:
尝试使用 sudo 安装“matplotlib”:
For python version 2.7
对于python 2.7版
$sudo pip install matplotlib
or
或者
For python version 3.x
对于 python 版本 3.x
$sudo pip3 install matplotlib