【问题标题】:cannot import matplotlib in jupyter无法在 jupyter 中导入 matplotlib
【发布时间】:2016-07-24 20:28:46
【问题描述】:

我已经在互联网上搜索了这个问题的简明答案,但似乎找不到。我正在将 jupyter 用于 python 2,并试图导入 matplotlib.pyplot 无济于事。 这是我正在运行的代码:

import matplotlib.pyplot as plt
%matplotlib inline

我收到的错误信息是:

    ---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-5-385145dcc870> in <module>()
----> 1 import matplotlib.pyplot as plt
      2 get_ipython().magic(u'matplotlib inline')

/Users/mbhall88/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/__init__.py in <module>()
    120 # cbook must import matplotlib only within function
    121 # definitions, so it is safe to import from it here.
--> 122 from matplotlib.cbook import is_string_like, mplDeprecation, dedent, get_label
    123 from matplotlib.compat import subprocess
    124 from matplotlib.rcsetup import (defaultParams,

/Users/mbhall88/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/cbook.py in <module>()
     31 from weakref import ref, WeakKeyDictionary
     32 
---> 33 import numpy as np
     34 import numpy.ma as ma
     35 

/Users/mbhall88/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/__init__.py in <module>()
    183         return loader(*packages, **options)
    184 
--> 185     from . import add_newdocs
    186     __all__ = ['add_newdocs',
    187                'ModuleDeprecationWarning',

/Users/mbhall88/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/add_newdocs.py in <module>()
     11 from __future__ import division, absolute_import, print_function
     12 
---> 13 from numpy.lib import add_newdoc
     14 
     15 ###############################################################################

/Users/mbhall88/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/lib/__init__.py in <module>()
     15 from .ufunclike import *
     16 
---> 17 from . import scimath as emath
     18 from .polynomial import *
     19 #import convertcode

ImportError: cannot import name scimath

我已经更新了 matplotlib、numpy、scimath、scipy 和 anaconda navigator(基本上更新了我能想到的所有内容)并重新启动了所有内容,但我仍然收到此错误。

抱歉,如果这是我错过的一些简单的事情,但我不是很能破译其中一些错误消息。

提前谢谢你。

【问题讨论】:

    标签: python-2.7 numpy matplotlib jupyter


    【解决方案1】:

    这是因为您的 Enthought canopy 分布中的 numpy 与您的 anaconda env 中的 numpy 冲突,并且 matplotlib 可能是针对 enthought numpy 构建的,但正在针对 conda 运行(反之亦然...)

    最简单的解决方法是卸载 enthought(或 conda)并且只使用一个。更难/更混乱的解决方法是将经过深思熟虑的 python 从你的 sys.path 和 PythonPath 中踢出,如果它存在的话。

    【讨论】:

    • 非常感谢。这让我困扰了好几个月。
    猜你喜欢
    • 2017-02-03
    • 2016-11-27
    • 1970-01-01
    • 2018-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-18
    • 2020-11-06
    相关资源
    最近更新 更多