I know that this is quite a common problem but when I installed this package I can't seem to get pyplot to be imported with matplotlib. My computer is currently running Pop os and I am using Pycharm as my IDE. When I run anything involved pyplot I get an the console prints out
Traceback (most recent call last):
File "/home/msm/PycharmProjects/Beginner/testing.py", line 1, in <module>
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package
I have already tried the following
sudo apt-get install python3-matplotlib in the terminal
Searching for the package within Pycharm
Updating Python
Any help would be greatly appreciated.
try:
pip install matplotlib
if it isn't working try:
pip install --upgrade pip
and try it again
if it isn't working again try start terminal with administrator and add python -m to head of code
I installed Python and Jupyter through Anaconda. I tried to reinstall Matplotlib and, after this, probably this installation created some error when I try to import Matplotlib. Always when I try to import Matplotlib I have the error below.
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-15-a0d2faabd9e9> in <module>
----> 1 import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
I tried installing Matplotlib again through the Anaconda Navigator. I open it\ go to 'Environments'\ base(root)\ all.
Then, I select Matplotliband click 'Apply'. It does the installation. But afterwards, Matplotlib is still giving the same error.
import matplotlib.pyplot as plt
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-16-a0d2faabd9e9> in <module>
----> 1 import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
I would expect to get the import done, and start working with Matplotlib to create plots, but I only get this error.
If you have mapped your command line interpreter to python, open command prompt (Windows) or Terminal (Mac) and type:
conda install -c conda-forge matplotlib
This will automatically install matplotlib for you. You can search other packages on https://anaconda.org/ for future downloads.
There are similar questions posted on Stackoverflow that did not seem to work for me. I am trying to install the pylab module for Python. I am using OSX. I have Python 2.7, 3.6, and 3.7 installed and have been running IDLE from 3.6. I also installed Anaconda. It looks like I have the modules and libraries I need here:
/Users/[username]/anaconda3/lib/python3.6/site-packages/matplotlib
There is also a pylab.py in that same site-packages directory.
But when I run a simple Python program with:
from pylab import plot, show
I get this error message:
Traceback (most recent call last):
File "/Users/[username]/Desktop/Python/graph.py", line 1, in <module>
from pylab import plot, show
ModuleNotFoundError: No module named 'pylab'
Not sure what I am doing wrong.
I'm running iPhyton Notebooks and I'm trying to import the Seaborn package. When I try to import it from the Terminal, it loads up fine, but when I import it through iPython Notebooks, it give me the following error.
I have even tried to re-install Seaborn using both Conda and Pip inside iPython notebooks and still it wont work.
Any idea why?
Thanks.
ImportError Traceback (most recent call last)
<ipython-input-1-417274a1ae6c> in <module>()
1 get_ipython().system(u'conda install seaborn')
2 get_ipython().system(u'pip install seaborn')
----> 3 import seaborn as sb
4
ImportError: No module named seaborn
Try this
import sys
print sys.path
sys.path.append('<path to package in your syste>')
import seaborn
In my Ubuntu 14.4LTS the packages get installed in the following folder
/usr/local/lib/python2.7/dist-packages
So I simply add the package path at run time
Donit install Ipython on all your system. Install it only in the environments you want it. Otherwise Ipython will look for modules in the default path instead of the environment's path.
This is probably where your ipython is looking:
/home/user/anaconda2/lib/python2.7/
It should be looking for modules here:
/home/user/anaconda2/envs/name-of-env/lib/python3.4/
To check the path you type:
import sys
sys.path
Try entering the following in your terminal:
conda install seaborn
It will install seaborn and make it available for you to import into your notebook
Open anaconda prompt and Type
pip install seaborn
I have such imports and code:
import pandas as pd
import numpy as np
import statsmodels.formula.api as sm
import matplotlib.pyplot as plt
#Read the data from pydatasets repo using Pandas
url = './file.csv'
white_side = pd.read_csv(url)
#Fitting the model
model = sm.ols(formula='budget ~ article_size',
data=white_side,
subset=white_side['producer'] == "Peter Jackson")
fitted = model.fit()
print fitted.summary()
After execution of this code I have such errors:
/usr/bin/python2.7 /home/seth/PycharmProjects/osiris_project/PMN_way/start.py
Traceback (most recent call last):
File "/home/seth/PycharmProjects/osiris_project/PMN_way/start.py", line 5, in <module>
import matplotlib.pyplot as plt
File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 98, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/__init__.py", line 25, in pylab_setup
globals(),locals(),[backend_name])
ImportError: No module named backend_tkagg
Process finished with exit code 1
I`m using openSUSE and pycharm community edition latest version with installed pandas, numpy, etc
How can i fix this problem?
I've seen this before, also on openSUSE (12.3). The fix is to edit the default matplotlibrc file.
Here's how you find where the default matplotlibrc file lives, and where it lives on my machine:
>>> import matplotlib
>>> matplotlib.matplotlib_fname()
'/usr/lib64/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc'
The backend setting is the first configuration option in this file. Change it from TkAgg to Agg, or to some other backend you have installed on your system. The comments in the matplotlibrc file list all backends supported by matplotlib.
The backend specified in this file is only the default; you can still change it at runtime by adding the following two lines, before any other matplotlib import:
import matplotlib
matplotlib.use("Agg") # or whichever backend you wish to use
I use openSuse 13.1 and had the same error "ImportError: No module named backend_tkagg".
I solved it by using this suggestion: http://forums.opensuse.org/showthread.php/416182-Python-matplolib.
I've installed the python-matplotlib-tk package, and now it is working just fine.
E.g. you can use: zypper install python-matplotlib-tk
I tried various solutions, only this works for me:
sudo pip install matplotlib --upgrade
I was able to fix this by putting
import matplotlib.backends.backend_tkagg
above
import matplotlib.pyplot as plt
Note, I received the same error while trying to run an executable generated using Py2exe.
Here is what I got when I ran TheProgram.exe from the command prompt:
>>TheProgram.exe
Traceback (most recent call last):
File "ThePythonScriptToMakeIntoExe.py", line 14, in <module>
File "C:\Python34\lib\site-packages\matplotlib\pyplot.py", line 109, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "C:\Python34\lib\site-packages\matplotlib\backends\__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
ImportError: No module named 'matplotlib.backends.backend_tkagg'
I add my answer for those who might encounter this problem using CARLA Simulator.
Using Python 3.6, and installing matplotlib v 2.2.5 solved this problem for me.
To remove matplotlib and install the right version you can run
pip uninstall -r requirements.txt
Then add matplotlib==2.2.5 to the requirement file and run pip install -r requirements.txt --user to install the correct versions.
If you are missing the requirements.txt file, here you are
Pillow>=3.1.2
numpy>=1.14.5
protobuf>=3.6.0
pygame>=1.9.4
matplotlib==2.2.5
future>=0.16.0
scipy>=0.17.0
In case you have different python versions and you would like to use a specific python version using py -<version> will use the right python version.
WARNING: Changing Path variable of the current Python version might be dangerous and specially for linux users it might cause that you can not open the terminal again. This is because different Python versions might not be compatible with the current pip version you are using. If it is too late for you and you already messed up with your terminal you can visit This tutorial to fix your issue.
After all of the fixes you might still get this error:
TypeError: blit() got an unexpected keyword argument 'colormode'
So you might want to edit the live_plotter.py file and remove colormode attribute from all the lines which are passing it to blit() method.
I faced this issue before, I solved it by using an old version of matplotlib which is version 3.0.0
if you don't have this version try pip install matplotlib==3.0.0
hope this was helpful!
I faced this issue while doing live plotting using the 2.2.2 version. Tried the following:
pip install matplotlib==3.0.0 --user
It's still an older version but it worked.
I solved the problem by setting the variable before starting python
export MPLBACKEND=Agg; python3
Taken from here.