Monday, May 14, 2018

Fixing the Matplotlib PyPlot import errors

About a week back, I was reinstalling Keras, TensorFlow and all the other libraries after a reformat of my PC. When I started verifying the library installations, I came across a strange error. When I tried to run a simple deep learning model, Python runtime crashed. As soon as I execute the script I was getting the "python.exe has stopped working" error message (I'm using Windows 10).

A little bit of debugging narrowed down the error to the following line in my script.

import matplotlib.pyplot as plt

(I was using matplotlib to graph the training history of the model. See "How to Graph Model Training History in Keras")

The error did not occur if I simply import matplotlib. It only occurred when specifically importing the pyplot module.

import matplotlib
# no errors

import matplotlib.pyplot as plt
# crash!!!

This is a known issue due to some library conflicts in the installation, which should hopefully be fixed in a future release. Until then, if you're getting this error, you can fix it by following the steps below.



Try them in order and see which step works for you.

1. Check if multiple versions of numpy is installed, and remove any unnecessary versions if possible.

2. Try updating matplotlib

conda update matplotlib

3. Force reinstall matplotlib using conda

conda install -f matplotlib

4. Clean out any version of matplotlib which might have been installed using pip

conda remove matplotlib
pip uninstall matplotlib
conda install matplotlib

5. If all other steps fail, try removing the conda version of matplotlib, and installing using pip instead

conda remove matplotlib
pip install matplotlib

Hopefully, these steps would help you get your matplotlib import working correctly again.

Related links,




Build Deeper: Deep Learning Beginners' Guide is the ultimate guide for anyone taking their first step into Deep Learning.

Get your copy now!

No comments:

Post a Comment