简体   繁体   English

无法在 Jupyter Notebook 中加载 matplotlib

[英]Unable to load matplotlib in Jupyter Notebook

I'm Unable to load matplotlib in Jupyter Notebook but woking fine in python command line shell,我无法在 Jupyter Notebook 中加载 matplotlib,但在 python 命令行 shell 中工作正常,

Is there anything I need to configure to make it working?我需要配置什么才能使它工作吗?

Following is the error I'm getting in Jupyter Notebook以下是我在 Jupyter Notebook 中遇到的错误

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-99ba79ecbbfb> in <module>()
----> 1 from matplotlib import pyplot as plt

ImportError: No module named matplotlib

And in command line I can access it like the following:在命令行中,我可以像下面这样访问它:

Python 3.7.3 (default, Mar 27 2019, 23:47:09) 
[Clang 10.0.0 (clang-1000.10.44.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from matplotlib import pyplot as plt
>>> 

Seems like it's working now I ran the following command as specified here似乎它现在正在工作,我运行了此处指定的以下命令

python3 -m pip install ipykernel
python3 -m ipykernel install --user

Thanks.谢谢。

One way is to check if you installed matplotlib using pip3 (if you used pip3 to install jupyter notebook , which looks like is your case).一种方法是检查您是否使用 pip3 安装了matplotlib (如果您使用 pip3 安装jupyter notebook ,这看起来就是您的情况)。

Another way is to add the path of site-wide packages (where of course matplotlib is installed).另一种方法是添加站点范围包的路径(当然安装 matplotlib 的位置)。 In your Jupyter notebook console:在您的 Jupyter 笔记本控制台中:

import sys
PATH = '/usr/lib64/python3.7/site-packages/'
sys.path.append(PATH)

Notebook is launched from another virtual python environment. Notebook 是从另一个虚拟 python 环境启动的。

You can check paths to python interpreters, that run your notebook and interactive shell:您可以检查运行笔记本和交互式 shell 的 python 解释器的路径:

import sys
print(sys.executable)

I'm sure, they will be different.我敢肯定,他们会有所不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM