【问题标题】:Error: Import matplotlib.pyplot as mlt in jupyter notebook in Mac错误:在 Mac 上的 jupyter notebook 中将 matplotlib.pyplot 导入为 plt
【发布时间】:2016-12-20 16:42:35
【问题描述】:
----------------------------------------------------------------
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

我想在 jupyter notebook 中导入 matplotlib.pyplot 但出现这些错误。我尝试将 matplotlibrc 文件添加为本网站 (Installation Issue with matplotlib Python) 但失败了。

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    我遇到了同样的问题。最新版本的jupytermatplotlib 似乎已解决此问题,并且在jupyter notebook 之前运行以下命令可解决我系统上的错误:

    (env)$ pip install --upgrade jupyter matplotlib
    

    这些是我的 virtualenv 中使用 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
    

    对于旧版本,还有其他解决方法: https://stackoverflow.com/a/35107136/2113258, https://stackoverflow.com/a/21789908/2113258

    【讨论】:

      【解决方案2】:

      先生运行命令后:

      pip install --upgrade jupyter matplotlib

      这个错误正在发生

      "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."
      

      并正确安装

      【讨论】:

        猜你喜欢
        • 2017-12-17
        • 1970-01-01
        • 2014-08-09
        • 2014-12-05
        • 2017-11-05
        • 1970-01-01
        • 2015-06-08
        • 1970-01-01
        • 2019-02-26
        相关资源
        最近更新 更多