-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: AttributeError: module 'matplotlib' has no attribute 'pyplot' on Mac #25506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can you simplify this to not use librosa? I am also confused by the traceback because there are two I am still suspicious that this is an installation issue. |
Yeah, I tried to use w/o librosa and got the same issue plotting a trivial graph. |
There is no way that the browser should be able to affect anything about the Python run time. If it is working in one browser and not another I suspect that this is due to using different kernels (and venvs) in each of those. Can you please start with on entirely fresh venv reproduce this? I think we would need to see both how you set up the env and the output of |
But that browser stuff, that's what exactly happened to me, weird. Anyways, thanks for the assistance, resolved. |
Hi, I had the exact same problem on Windows (very similar code to yours as I am also plotting spectograms. I tried so many things. It wouldn't even work in a new fresh venv, and the problem seemed to only occur in Jupyter Notebook and not in Spyder for example. I found out that it works if I do not import librosa.display. I think it messes up the import of matplotlib(.pyplot). Just import librosa and use librosa.display.X in the code. Hope this helps if it occurs in the future! |
Hi, I had this exact problem. I solved it by importing matplotlib.pyplot before importing librosa and it's sub components. Pretty easy fix but why I wonder 🤔 matplotlib version 3.7.1 |
this worked for me as well. |
As far as I can tell, this seems to be caused by the lazy loading of matplotlib in librosa's if TYPE_CHECKING:
import matplotlib
... to if True:
import matplotlib
... i.e., explicitly do the imports directly rather than with the lazy loader, then this problem doesn't seem to occur (for me at least). Note: if I librosa v0.9.2, i.e., the version before the lazy loading was introduced, then it works without a problem. |
This is a bug in matplotlib-inline: ipython/matplotlib-inline#24. If you check their imports, they import So explicitly importing |
This is not an issue in matplotlib-inline, but rather in librosa, caused by their lazy loading. See here. |
It is true that the problem is triggered by the lazy loading mechanism |
I'm not sure if "traditional import machinery" is contrasting with mpl'- |
FWIW, I've patched this particular issue from the librosa side after realizing that we didn't actually need to directly lazy-load mpl submodules. (I don't think it's "wrong" to do so, but since we don't need to, I've reworked it.) This will roll out in the next release (some time this summer), but has already merged to main: librosa/librosa#1722 |
Bug summary
I'm getting a weird error locally on my Mac in Jupyter Notebook while trying to plot the graph with
matplotlib
.The error is:
AttributeError: module 'matplotlib' has no attribute 'pyplot'
even though everything is imported correctly and code works on Google Colab.Code for reproduction
Actual outcome
Expected outcome
Plotted graph of mel spectrogram.
Additional information
I tried to reinstall it and import it in different ways, but it didn't help.
Operating system
MacOS
Matplotlib Version
3.7.1
Matplotlib Backend
module://matplotlib_inline.backend_inline
Python version
3.9.16
Jupyter version
6.5.3
Installation
pip
The text was updated successfully, but these errors were encountered: