matplotlib: RuntimeError: Python is not installed as a framework

前端 未结 6 2190
情深已故
情深已故 2020-12-23 14:04

This question has been asked before, in here, also here. However, the solution didn\'t fix the problem for my case.

The original error is, when I try to impor

相关标签:
6条回答
  • 2020-12-23 14:17

    I had the same issues in python 2.7 in virtualenv and I managed to fix those by simply downgrading matplotlib to version 2.1.0

    0 讨论(0)
  • 2020-12-23 14:24

    I was using pyenv so the matplotlibrc path wasn't in the home directory, so I created this script to figure the path out and change the backend to Tkagg:

    vim $(python -c "import os,matplotlib; print(os.path.join(os.path.dirname(matplotlib.__file__), 'mpl-data/matplotlibrc'));")
    

    This script should work with any python on your system though.

    0 讨论(0)
  • 2020-12-23 14:25

    I was also having the same error. What I have done is to install miniconda packages and using the pythonw. Python app was already installed in my mac. Installation is as simple as breaking an egg. Just bash the .sh file in the terminal.

    0 讨论(0)
  • 2020-12-23 14:27

    I run my script in virtualenv. Python version is 3.5.

    Add a line:

    backend: TkAgg
    

    in file:

    ~/.matplotlib/matplotlibrc
    

    This solved the problem.

    If you want to know more about why adding this solves the problem, you can read about customizing matplotlib's backend. And TkAgg solves this issue because of it's dependency with Tkinter.

    0 讨论(0)
  • 2020-12-23 14:33

    Below worked for me:

    import matplotlib  
    matplotlib.use('TkAgg')   
    import matplotlib.pyplot as plt  
    

    Reference: https://github.com/tensorflow/tensorflow/issues/2375

    0 讨论(0)
  • 2020-12-23 14:35

    I installed Jupyter Notebook in virtualenv and below worked for me:

    At Console:

    echo "backend: TkAgg" >> ~/.matplotlib/matplotlibrc
    pip install matplotlib==2.1.0
    

    On Notebook:

    import matplotlib
    

    Restart the kernel:

    dataframe.plot.hist()
    ...
    

    In my opinion, it will fix the error.

    0 讨论(0)
提交回复
热议问题