Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib TypeError when importing matplotlib.pyplot

I have just used conda to update my Anaconda installation and Matplotlib went from v1.4.0 to v1.4.2. However now all my Python jobs which use Matplotlib.pyplot are throwing exceptions.

Even the simple command:

import matplotlib.pyplot as plt

throws a TypeError exception, saying:

cannot return std::string from Unicode object

The traceback tells me the exception is occurring in the font_manager.py file, here:

try:
    font = ft2font.FT2Font(fpath)
except RuntimeError:
    verbose.report("Could not open font file %s" % fpath)
    continue
except UnicodeError:
    verbose.report("Cannot handle unicode filenames")
    continue

specifically at the line font = ft2font.FT2Font(fpath).

I tried going back to v1.4.0 of Matplotlib but it didn't fix the problem.

Then I edited font_manager.py to add a generic exception case:

except:
    verbose.report("Some stupid error occurred")
    continue

in the hope that it would temporarily get around the issue, which it did, but that error or something very similar to it occurred later. So then I removed the exception but the error is now still occurring at the later point in the code (so if I run import matplotlib.pyplot as plt it works, but doing other commands can fail).

I use Matplotlib to generate/update hundreds of graphs throughout the day and now everything is broken.

Please help! Thanks!

like image 691
Adrian Mc Avatar asked Jan 06 '15 16:01

Adrian Mc


1 Answers

It seems like uninstalling Anaconda and reinstalling a fresh version fixes the issue as mentioned by @pbreach, so closing this question out.

like image 198
Adrian Mc Avatar answered Oct 08 '22 23:10

Adrian Mc