简体   繁体   English

在 Jupyter Notebook 中导入 matplotlib 时找不到子包

[英]when importing matplotlib in Jupyter Notebook no subpackages found

I'm trying to import matplotlib.pyplot (ver 3.2.1) in Jupyter Notebook but keep getting an error.我正在尝试在 Jupyter Notebook 中导入 matplotlib.pyplot (版本 3.2.1),但一直出错。
It might be worth mentioning that I have ArcGIS on my laptop where there is Python 2.7 and Matplotlib of version 1, not 3. And steps listed below work fine in PyCharm.值得一提的是,我的笔记本电脑上有 ArcGIS,其中有 Python 2.7 和 Matplotlib 版本 1,而不是 3。下面列出的步骤在 Z4149CE0EE30A909A1F62C583FF202 中工作正常。

import matplotlib.pyplot as plt

ModuleNotFoundError: No module named 'matplotlib.pyplot

I tried uninstalling the whole thing with running pip uninstall matplotlib from command line (using Windows) and install it then back, but it also doesn't seem to have any effect.我尝试通过运行 pip uninstall matplotlib 从命令行(使用 Windows)卸载整个东西,然后再安装回来,但它似乎也没有任何效果。

Just importing matplotlib works fine until I run some code that includes its functions.只需导入 matplotlib 就可以正常工作,直到我运行一些包含其功能的代码。 Then errors arise, ie然后出现错误,即

import matplotlib

This cell runs with no errors.此单元格运行没有错误。 Then I try to display some basic stuff:然后我尝试展示一些基本的东西:

x = [0, 1, 2, 3, 4]
y = [2, 2, 2, 2, 2]
df = pd.DataFrame([x,y], columns=['a','b','c','d','f'])
df['b'].hist()
matplolib.pyplot.show() 

and get multiple traceback outputs并获得多个回溯输出

~\Anaconda3\lib\site-packages\pandas\plotting\_core.py in _get_plot_backend(backend)
   1599         # Because matplotlib is an optional dependency and first-party backend,
   1600         # we need to attempt an import here to raise an ImportError if needed.
-> 1601         import pandas.plotting._matplotlib as module
   1602 
   1603         _backends["matplotlib"] = module

ModuleNotFoundError: No module named 'matplotlib.artist'

I also tried this:我也试过这个:

%matplotlib
import matplotlib.pyplot as plt

Which resulted in yet another error:这导致了另一个错误:

~\Anaconda3\lib\site-packages\IPython\core\pylabtools.py in find_gui_and_backend(gui, gui_select)
    286         # overwritten that.
    287         # WARNING: this assumes matplotlib 1.1 or newer!!
--> 288         backend = matplotlib.rcParamsOrig['backend']
    289         # In this case, we need to find what the appropriate gui selection call
    290         # should be for IPython, so we can activate inputhook accordingly

AttributeError: module 'matplotlib' has no attribute 'rcParamsOrig'

Help me please to resolve this issue.请帮我解决这个问题。

Try to reinstall the module as follows.尝试如下重新安装模块。 A broken installation could lead to this error.损坏的安装可能会导致此错误。

pip install --upgrade --force-reinstall matplotlib 

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

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