cannot import name 'animation' from 'matplotlib' - matplotlib

I try import matplotlib with:
import matplotlib.pyplot as plt
But I get this error:
ImportError: cannot import name 'animation' from 'matplotlib' (C:\Users\David\AppData\Roaming\Python\Python37\site-packages\matplotlib_init_.py).
I removed and reinstalled matplotlib, I tried installing older matplotlib version.

In my case, updating matplotlib and restarting the kernel (in Jupyter notebook) solved the issue.
I installed this version:
pip install --user matplotlib==3.5.0b1
I realise this question is 10 months old now.
Hope it helps other users.

Related

ANACONDA "ModuleNotFoundError: No module named 'pandas.tslib'" in pandas python

I would like to run below code but I received an error in my anaconda environment. How can I solve this issue in Anaconda? Please help!
Thank you.
import pandas as pd
import numpy as np
from statsmodels.tools.eval_measures import rmse, aic
from darts import TimeSeries
from darts.utils.timeseries_generation import gaussian_timeseries, linear_timeseries
from darts.models import RNNModel, TCNModel, TransformerModel, NBEATSModel, BlockRNNModel
from darts.metrics import mape, smape
from darts.utils.timeseries_generation import datetime_attribute_timeseries
After I tried
conda uninstall pandas
conda install pandas
Error message becomes :
Check the corresponding path, if you do not find pandas._libs.tslib module then you would have to uninstall pandas and reinstall again.
conda uninstall pandas
conda install pandas
You can also check if the version of pandas you are using is consistent with the version of python

Pip install does not work, matplotlib seems to be broken, pyenv and fresh new install doesn't work

So I wanted to import matplotlib to my virtual python version of 3.10.0 (and other versions). I install it as usual:
pip install matplotlib
Everything seems to work, no errors show up with pip. But when I try to run this code snippet in vs code (to see if mpl works):
import matplotlib
print(matplotlib.__version__)
It outputs this:
File "/Users/XYZ/Desktop//pienv.py", line 1, in <module>
import matplotlib
File "/Users/XYZ/Desktop//matplotlib.py", line 1, in <module>
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package
But when I do the same in the terminal it outputs the correct version.
It doesn't matter if I have python installed with dmg file or with pyenv, result is the same.
I tried to format operating system to ensure there is no os trash that might be getting in a way. Then I just installed python with pyenv.
I'm using osx 12.0.1
My vscode setup is straightforward, just python extension and python interpreter set to what pyenv has as a local python.
Is there that can be done, or that I'm doing wrong?
Found the answer.
It's just a stupid thing.
Don't name your projects with the names of your libraries when they're in the same directory.

ImportError: No module named 'numpy.testing.nosetester'

I am facing an issue when I run 'from sklearn.model_selection import train_test_split' in jupyter notebook. I tried to upgrade/reinstall numpy, scipy and pandas but still cannot fix the problem. Please help. Thanks in advance.
Upgrade numpy/scipy.
( Possible duplicate:
ModuleNotFoundError: No module named 'numpy.testing.nosetester' )
Using Python3:
pip3 install numpy==1.16.4

I want to use pandas2ri in JUPYTER but tzlocal issue?

Everytime I try to import the pandas2ri in jupyter, python interface:
from rpy2.robjects import pandas2ri
I get the following error:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-28-cc52694d111a> in <module>()
----> 1 from rpy2.robjects import pandas2ri
/Users/sondosayyash/anaconda/lib/python3.6/site-packages/rpy2/robjects/pandas2ri.py in <module>()
21 import numpy
22 import pytz
---> 23 import tzlocal
24 import warnings
25
ModuleNotFoundError: No module named 'tzlocal'
I tried to use
from dateutil.tz import tzlocal
but that didn't seem to fix the issue.
I've already installed tzlocal and it is on my computer. When I import pandas2ri on ipython, there is no problem.. the problem only occurs when calling in the jupyter environment.
this is the message I get when I try to install tzlocal again:
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020.
Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Requirement already satisfied: tzlocal in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (1.5.1)
Requirement already satisfied: pytz in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from tzlocal) (2017.2)
I had a similar issue when running rpy2 in Jupyter. I did not have the package installed previously. I just installed the package and the error went away. You can try installing the package again to see if it helps resolve your issue.
pip install tzlocal
I must add that I am using Python 3.6.8 not 2.7
If using conda:
conda install tzlocal
worked.
I had a similar issue as yours. It turns out that my local lib did not have the tzlocal package. So I installed the package through Anaconda prompt:
pip install tzlocal
And the issue is gone.

AttributeError: module 'matplotlib' has no attribute 'pyplot'

I am running Anaconda 4.2.9 and Python 3.5.2 on MacOS 10.12. Whenever I try the simple command
import matplotlib.pyplot as plt
I get the following error message
[1]: import matplotlib.pyplot as plt
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-1-eff513f636fd> in <module>()
----> 1 import matplotlib.pyplot as plt
/Users/ghoetker/anaconda/lib/python3.5/site-packages/matplotlib/pyplot.py in <module>()
8 import matplotlib
9
---> 10 import matplotlib.pyplot as plt
11 import matplotlib.animation as manimation
12
AttributeError: module 'matplotlib' has no attribute 'pyplot'
I get this error whether I use iPython, a Jupyter Notebook, PyCharm, Spyder or Rodeo. I've used conda to uninstall and reinstall matplotlib to no avail. The really odd thing is that it worked once this morning, but hasn't since. I'm not aware of anything I changed in the interim. I've found that if I downgrade to matplotlib 1.5.1, it works just fine. However, that requires some more meaningful downgrades, like going from Spyder 3 to Spyder 2. So, I'd really like to figure out how to use the current version of matplotlib.
I would really appreciate any recommendations or pointers anyone can provide. Obviously, I'm happy to provide any additional information that would help with debugging.
I tried the following sequence of commands and it worked for me:
conda uninstall pyzmq
conda install pyzmq
conda install jupyter