RuntimeError: Invalid DISPLAY variable April 11, 2023 by Tarik You must declare matplotlib.use('agg') before import pylab as plt. Reference