首页 > 解决方案 > matplotlib.pyplot 导入在 ipython 中失败,但在 jupyter 中有效

问题描述

当我尝试在 ipython 中导入 pyplot 时出现这个长错误。当我在 jupyter notebook 中尝试相同时,一切正常。我想我已经尝试了所有关于 pyplot 导入错误的建议。我尝试重新安装 matplotlib、ipykernel、zmq 等,我尝试回滚到旧版本。我已经尝试从笔记本和我的 ipython 内核中匹配 sys.path,但没有成功。

我正在为 ipython 内核使用 python 3.7、Windows 10、ConEmu。

from matplotlib import pyplot
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-02aaac1810fb> in <module>
----> 1 from matplotlib import pyplot

C:\ProgramData\Python3\Continuum\anaconda3\lib\site-packages\matplotlib\pyplot.py in <module>
   2347     dict.__setitem__(rcParams, "backend", rcsetup._auto_backend_sentinel)
   2348 # Set up the backend.
-> 2349 switch_backend(rcParams["backend"])
   2350
   2351 # Just to be safe.  Interactive mode can be turned on without

C:\ProgramData\Python3\Continuum\anaconda3\lib\site-packages\matplotlib\pyplot.py in switch_backend(newbackend)
    219         else "matplotlib.backends.backend_{}".format(newbackend.lower()))
    220
--> 221     backend_mod = importlib.import_module(backend_name)
    222     Backend = type(
    223         "Backend", (matplotlib.backends._Backend,), vars(backend_mod))

C:\ProgramData\Python3\Continuum\anaconda3\lib\importlib\__init__.py in import_module(name, package)
    125                 break
    126             level += 1
--> 127     return _bootstrap._gcd_import(name[level:], package, level)
    128
    129

C:\ProgramData\Python3\Continuum\anaconda3\lib\site-packages\matplotlib\backends\backend_tkagg.py in <module>
      1 from . import _backend_tk
----> 2 from .backend_agg import FigureCanvasAgg
      3 from ._backend_tk import (
      4     _BackendTk, FigureCanvasTk, FigureManagerTk, NavigationToolbar2Tk)
      5

C:\ProgramData\Python3\Continuum\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in <module>
     43
     44 if _has_pil:
---> 45     from PIL import Image
     46
     47 backend_version = 'v2.2'

C:\ProgramData\Python3\Continuum\anaconda3\lib\site-packages\PIL\Image.py in <module>
     93     # Also note that Image.core is not a publicly documented interface,
     94     # and should be considered private and subject to change.
---> 95     from . import _imaging as core
     96
     97     if __version__ != getattr(core, "PILLOW_VERSION", None):

ImportError: DLL load failed: The specified module could not be found.

标签: pythonpython-3.xmatplotlibdll

解决方案


推荐阅读