I am getting this error when I am trying to import "matplotlib.pyplot". I cant even install matplotlib.pyplot through conda install.
It shows this:
3import matplotlib.pyplot Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'matplotlib.pyplot'
7 Answers
As reported here, when you use Anaconda, install the packet using conda. In this case, the right instruction to use (on Ubuntu 18.04) is:
conda install -c conda-forge matplotlibThis will solve the problem.
If you use pip (you can), you will mess up all the dependencies (and for instance, the probability that other scripts/programs do not work anymore is not null: if you use Spyder, you will have big dependencies problem to face).
Optional:
In order to always avoid problem like this, I recommend you to use Virtual Enviroment:
Whats is it?
Geeksforgeeks explains it clearly.
How?
A step-by-step guide is always useful.
It could be that it's running your default Python installation instead of the one installed with Anaconda. Try prepending this to the top of your script:
#!/usr/bin/env pythonIf that does not work, try installing matplotlib with pip, then try again:
pip install matplotlibLet me know if that works for you.
2Just open anaconda prompt and use either of the below command to install the package. This solved my issue.
- conda install -c plotly chart-studio
or
- conda install -c plotly/label/test chart-studio
I had the same issue for days, just solved it by adding "%matplotlib inline" on top of "import matplotlib.pyplot as plt"
So enter this to import mathplotlib.pylot:
%matplotlib inline
import matplotlib.pyplot as plt Make sure Matplotlib is accessed in the Same Conda Environment as it was installed.
In the case below, Matplotlib was installed in pytorch environment and not the base environment.
Hence when run in the pytorch environment it gets imported, but doesn't get imported in base environment.
TERMINAL
#Installation
(pytorch) F:\Script\Ai\Pytorch>conda install -c conda-forge matplotlib
#Check installation in pytorch Environment
(pytorch) F:\Script\Ai\Pytorch>python
>>> import matplotlib
>>> print('matplotlib: {}'.format(matplotlib.__version__))
matplotlib: 3.3.4
#Import Error in base Environment
(base) F:\Script\Ai\Pytorch>python
>>> import matplotlib
Traceback (most recent call last): File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'matplotlib' Switch to the correct environment before installing.
conda activate environment_name_here
conda install matplotlibIn my case, I had an environment for a jupyter notebook, but installed in initially in a new terminal window which defaulted to the base environment.
Check if the ...../python3.x/site-packages is listed within sys.path. If not append it with sys.path.append('.....python3.8/site-packages')