Reputation: 249
I am using a plotting function that utilizes matplotlib and all of a sudden, it has stopped working and is returning the following error.
from matplotlib.dates import (HOURS_PER_DAY, MIN_PER_HOUR, SEC_PER_MIN,
ImportError: cannot import name 'warnings' from 'matplotlib.dates'
Is there a known fix for this?
Thanks
Upvotes: 4
Views: 2733
Reputation: 310
I had the same issue... Am using python-3.6.13, conda-4.9.2, backtrader-1.9.76.123.dist-info.
It seems matplotlib version I was using (matplotlib-3.3.4) were the issue, even importing warnings (import warnings) did not resolve.
The solution for me was:
pip uninstall matplotlib
pip install matplotlib==3.2.2
Hope to help, thank you!
Upvotes: 1
Reputation: 66
Let me guess ... You are using backtrader and had this issue while using it. The error you have is :
File "/xxx/backtrader/plot/locator.py", line 35, in <module>
from matplotlib.dates import (HOURS_PER_DAY, MIN_PER_HOUR, SEC_PER_MIN,
ImportError: cannot import name 'warnings' from 'matplotlib.dates'
The root cause of the error is that at line 35 of above mentionned file (locator.py) there is an attempt to import "warnings" from matplotlib.dates :
from matplotlib.dates import (HOURS_PER_DAY, MIN_PER_HOUR, SEC_PER_MIN,
MONTHS_PER_YEAR, DAYS_PER_WEEK,
SEC_PER_HOUR, SEC_PER_DAY,
num2date, rrulewrapper, YearLocator,
MicrosecondLocator, warnings)
But if you look at the doc or the code, you will find that there is no warnings in matplotlib.dates. Digging in this file history on github, one can find that a line :
import warnings
have been removed on 7 sept 2019, this is probably the reason of the issue you noticed. In Backtrader, there is a pull request awaiting for this issue : https://github.com/mementum/backtrader/pull/418
You can either apply the fix yourself to the code if you forked it, or wait for the PR to be merged
Upvotes: 5