question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

do not always import matplotlib

See original GitHub issue

librosa always imports matplotlib, even if you are doing pure analysis and have no interest in graphing.

This is inconvenient for batch soundfile analysis, as matplotlib has a large memory footprint, and an even larger file handle footprint. Moreover, if you run matplotlib in certain environments (I’m using tornado to analyse soundfiles on request) it seems to leak file handles.

Whilst the file handle leak is not, AFAICT, librosa’s problem per se, I’ve run into this issue in enough circumstances to feel that matplotlib should be considered something to be imported only when strictly required, and the memory problem alone is annoying when processing thousands of files in a multiprocess batch.

At first glance it seems that avoiding this could be as simple as only importing librosa.display on demand as opposed to in the root __init__.py.

Would it be worth me filing a pull request to do that?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
TimSchmeiercommented, May 4, 2016

FYI: Instead of using the above hack this solved a number of librosa/matplotlib import issues for me

import matplotlib
matplotlib.use('Agg')
1reaction
howthebodyworkscommented, May 11, 2016

Yes, I haven’t mentioned the details here because it’s one of those irritating things that lies at the intersection of several projects. But for other weary travellers, there the issue is that gc does not always close files at the best of times, and that the quirky matplotlib backend opens lots of files for reasons to do with fonts. The problem seems to arise especially often if you are using something that does live code reloading, such as a web development server.

There are a couple of long-delayed matplotlib backend changes which will radically change the font handling when they land, although they are many months in review already: https://github.com/matplotlib/matplotlib/pull/5414 https://github.com/matplotlib/matplotlib/pull/4143

But in the mean time @TimSchmeier 's tip actually does ease the issue even though without the MPL backend; the Agg Matplotlib backend can run for a lot more code iterations (at least on my python) before running out of file handles. I don’t know why.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Importing matplotlib does not work - Stack Overflow
really simple: Your matplotlib was linked against libpng15, but that isn't found by your run-time. So you might search for that file, ...
Read more >
What Is Matplotlib In Python? How to use it for plotting?
Matplotlib is a cross-platform, data visualization and graphical plotting library for Python and its numerical extension NumPy.
Read more >
How-To — Matplotlib 1.3.1 documentation
Find all objects in a figure of a certain type¶. Every matplotlib artist (see Artist tutorial) has a method called findobj() that can...
Read more >
Fixing common date annoyances - Matplotlib
you will see that the x tick labels are all squashed together. import matplotlib.cbook as cbook import matplotlib.dates as mdates import ...
Read more >
Image tutorial — Matplotlib 3.6.2 documentation
For example, changing the colormap is not possible from cells below the cell that ... import matplotlib.pyplot as plt import matplotlib.image as mpimg ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found