简体   繁体   中英

How to solve the error when importing matplotlib in Anaconda on macOS?

I am using Python 3.6.5 in macOs 10.13.6 and I can not import matplotlib . I have uninstalled and reinstalled matplotlib with conda without results.

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'

As mentioned by ImportanceOfBeingErnest it seems that matplotlib cannot import numpy, so try to uninstall and reinstall numpy with conda and tell us what you get. This seems to be a duplicate: How to fix AttributeError: module 'numpy' has no attribute 'square' Where your problem has been solved ;)

However it seems to me that when installing Anaconda, matplotlib and numpy are both preinstalled. Did you make change is these installations at some point ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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