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

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

Related

pandas and matplotlib not found on my tensorflow conda environment

I use a MacBook pro-2015, and I use the monetary.
I was able to pip install tensorflow to a new conda environment, but after it, pandas and matplotlib was no longer found.
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
import pandas as pd
Below is the traceback of error:
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 2
1 import numpy as np
----> 2 import matplotlib.pyplot as plt
3 import tensorflow as tf
4 import pandas as pd
ModuleNotFoundError: No module named 'matplotlib'
I have been able to solve this problem
I created a conda environment "myenv" where I installed tensorflow
Then I activated the conda environment in my terminal using
conda activate myenv
Then I installed the packages/libraries that I need
conda install pandas
conda install matplotlib
Just use this method to install any package into any environment you are working on

import yfinance issue - numpy dependency problem? Need to uninstall then reinstall numpy every time. Code works from CLI, but not in PyCharm

I am trying to use the yfinance module. I have a venv set up. If I run my code from the command line it works. If I run it inside PyCharm it throws this import error. Doing pip uninstall -y numpy and then pip install numpy fixes the problem, but I have to do this every day. I'm very confused on what is the issue. Anyone have any tips?
It is failing at literally the first line of code which is the import yfinance line. Here is the traceback:
Traceback (most recent call last):
File "/Users/MikeGuglielmo/Desktop/python_code.py/python_distilled/practice.py/main.py", line 1, in
import yfinance as yf
File "/Users/MikeGuglielmo/Desktop/python_code.py/options_project/venv/lib/python3.9/site-packages/yfinance/init.py", line 23, in
from .ticker import Ticker
File "/Users/MikeGuglielmo/Desktop/python_code.py/options_project/venv/lib/python3.9/site-packages/yfinance/ticker.py", line 27, in
import pandas as _pd
File "/Users/MikeGuglielmo/Desktop/python_code.py/options_project/venv/lib/python3.9/site-packages/pandas/init.py", line 16, in
raise ImportError(
ImportError: Unable to import required dependencies:
numpy:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
The Python version is: Python3.9 from "/Users/MikeGuglielmo/Desktop/python_code.py/options_project/venv/bin/python"
The NumPy version is: "1.23.3"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'

ImportError Pandas in Jupiter notebook - Not looking at venv packages

I installed pandas via pip in my virtualenv venv.
When I run import pandas as pd, I get the following error:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-588656c123e4> in <module>
3 import tarfile #2
4 from six.moves import urllib #3
----> 5 import pandas as pd #4
ModuleNotFoundError: No module named 'pandas'
I am running Jupiter notebook in the virtual environment. To make sure it installed properly, I opened the python in the virtualenv and ran the import, and it worked fine, what could be the issue? Could it be that though I ran Jupiter Notebook in my venv its not looking at the packages in the virtual environment?
Edit 1: I installed pandas on my machine, not in the virtual machine, and that resolved my issue. However, I want the notebook to look at the packages in my virtual environment, how do I do that?
Try running this in a Jupyter cell
!pip install pandas

cannot import name 'animation' from '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.

matplotlib module not found using jupyter notebook

I'm just trying to import matplotlib.pyplot using a jupyter notebook. I get the attached error. I have a hunch it has something to do with pip / matplotlib not being in the correct folder / environment but I don't know how to set up my environment so that it can access pip and all of the python modules that are pre-installed!
I moved the entire python folder into the folder I activated jupyter notebook out of, but then nothing else worked.
import matplotlib.pyplot as plt
I expected no response (successful) but got:
ModuleNotFoundError Traceback (most recent call last)
in
----> 1 import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
The notebook is trusted, when I run I get a terminal response that looks like:
Starting buffering for 25c7e3d9-8a1c-486d-848e-0fe7e0298dc7:02a1acc4bbb84ca88e1eb4ec9aa13576