ImportError: Cannot load backend ‘TkAgg’ which requires the ‘tk’ interactive framework, as ‘headless’ is currently running

What solved the problem for me was to restart my kernel, import the following first:

import matplotlib
matplotlib.use('TKAgg')

Then,

import matplotlib.pyplot as plt

You probably imported matplotlib with another framework before you tried to change to TKAgg. Restart your kernel.

Leave a Comment