简体   繁体   中英

Error: Import matplotlib.pyplot as mlt in jupyter notebook in Mac

----------------------------------------------------------------
RuntimeError                  Traceback (most recent call last)
<ipython-input-9-e4a9b95bd07b> in <module>()
      1 import pandas as pd
----> 2 import matplotlib.pyplot as plt

/Users/Nima/miniconda3/lib/python3.5/site-packages/matplotlib/pyplot.py in <module>()
    112 
    113 from matplotlib.backends import pylab_setup
--> 114 _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
    115 
    116 _IP_REGISTERED = None

/Users/Nima/miniconda3/lib/python3.5/site-packages/matplotlib/backends/__init__.py in pylab_setup()
     30     # imports. 0 means only perform absolute imports.
     31     backend_mod = __import__(backend_name,
---> 32                              globals(),locals(),[backend_name],0)
     33 
     34     # Things we pull in from all backends

/Users/Nima/miniconda3/lib/python3.5/site-packages/matplotlib/backends/backend_macosx.py in <module>()
     22 
     23 import matplotlib
---> 24 from matplotlib.backends import _macosx
     25 
     26 

RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are Working with Matplotlib in a virtual enviroment see 'Working with Matplotlib in Virtual environments' in the Matplotlib FAQ

I want to import the matplotlib.pyplot in jupyter notebook but got these errors. And I tried to add matplotlibrc file as this website ( Installation Issue with matplotlib Python ) but failed.

I ran into the same issue. This seems to be fixed with latest versions of jupyter and matplotlib , and running the following prior to jupyter notebook resolves the error on my system:

(env)$ pip install --upgrade jupyter matplotlib

These are the versions of packages in my virtualenv with python 2.7.10:

matplotlib==2.0.0
jupyter==1.0.0
jupyter-client==5.0.0
jupyter-console==5.1.0
jupyter-core==4.3.0
ipython==5.2.2
ipython-genutils==0.1.0

For older versions, there are other workarounds: https://stackoverflow.com/a/35107136/2113258 , https://stackoverflow.com/a/21789908/2113258

sir after running the command:

pip install --upgrade jupyter matplotlib

This error is now occurring

"ERROR: Could not install packages due to an EnvironmentError: [WinError 5] Access is denied: 
'c:\\users\\nadee\\anaconda3\\lib\\site-packages\\matplotlib\\backends\\_backend_agg.cp37-win_amd64.pyd'
 Consider using the `--user` option or check the permissions."

and install properly

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