How to fix matplotlib OSError: 'xkcd' not found in the style library

Problem:

While trying to enable the matplotlib xkcd style using

plt.style.use("xkcd")

you see the following error message:

OSError: 'xkcd' not found in the style library and input is not a valid URL or path; see `style.available` for list of available styles

Solution

You can’t enable xkcd-style plots by running plt.style.use("xkcd"). Instead, use with plt.xkcd():

with plt.xkcd():
    # TODO your plotting code goes here!
    # plt.plot(x, y) # Example