For example, with the GTKAgg backend selected in
~/.matplotlib/matplotlibrc, running cmd.py without X raises:
Traceback (most recent call last):
File "./cmd.py", line 32, in <module>
from matplotlib import pyplot as _pyplot
...
RuntimeError: could not create GdkCursor object
from matplotlib import pyplot as _pyplot
from matplotlib.lines import Line2D as _Line2D
#from matplotlib.animation import FuncAnimation as _FuncAnimation
-except ImportError as e:
+except (ImportError, RuntimeError) as e:
_pyplot = None
_matplotlib_import_error = e
import numpy as _numpy