matplotlib: RuntimeError: Python is not installed as a framework

Below worked for me:

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

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


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.