在macOS上的Anaconda中导入matplotlib时如何解决错误?

时间:2018-07-21 16:44:52

标签: python matplotlib

我在Python 3.6.5中使用macOs 10.13.6,但无法导入matplotlib。 我已卸载matplotlib并重新安装了conda,但没有结果。

Python 3.6.5 | packaged by conda-forge | (default, Apr  6 2018, 13:44:09)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/sergiobacelar/anaconda3/lib/python3.6/site-packages/matplotlib/__init__.py", line 127, in <module>
    from . import cbook
  File "/Users/sergiobacelar/anaconda3/lib/python3.6/site-packages/matplotlib/cbook/__init__.py", line 2640, in <module>
    class _StringFuncParser(object):
  File "/Users/sergiobacelar/anaconda3/lib/python3.6/site-packages/matplotlib/cbook/__init__.py", line 2652, in _StringFuncParser
    _funcs['quadratic'] = _FuncInfo(np.square,
AttributeError: module 'numpy' has no attribute 'square'

1 个答案:

答案 0 :(得分:1)

正如ImportanceOfBeingErnest所述,matplotlib似乎无法导入numpy,因此请尝试使用conda卸载并重新安装numpy,并告诉我们您得到了什么。 这似乎是重复的:How to fix AttributeError: module 'numpy' has no attribute 'square' 您的问题已解决的地方;)

但是,在我看来,安装Anaconda时,会同时预安装matplotlib和numpy。您是否在某些时候更改了这些安装?