I am trying to use matplotlib. However, when I type import matplotlib, I get the following error:
ImportError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package
I installed matplotlib using pip install matplotlib.
How do I fix this?
Thanks!
IDLE doesn't have all packages; some are more easily available (and easily installable) with Continuum's Anaconda. You can run Python code with this, and it simplifies installing packages.
Related
Here is the code that I used:
import math
import matplotlib.pyplot as plt
The error message was:
no module named 'matplotlib'
I have tried:
pip install matplotlib
python3 install mat plotlib
Tried updating Anaconda Navigator to the latest version.
Tried uninstalling and reinstalling Python 3.10.5
Tried using Visual Studio Code and individual Python files (I'll try Jupyter too).
conda update --all
python - version says that I have Python version 3.6.13
After all of that, I still get the same error that there is no module named matplotlib
The answer was that I had never actually attempted to access matplotlib outside of Jupyter Notebooks. I was only meant to access it inside of Jupyter. I created a virtual environment and that didn't work. I also did conda install matplotlib and that destroyed my Python install and I had to reinstall everything.
I just set up the VS Code with all the Python extensions. Python version is 3.8.3 through Anaconda. The interpreter is venv. When I run this code
import matplotlib.pyplot as plt
An error shows -
Exception has occurred: AttributeError
module 'sip' has no attribute 'setapi'
File "C:\test.py", line 145, in <module>
import matplotlib.pyplot as plt
I've tried uninstalling and reinstalling matplotlib, but to no avail.
This worked for me.
python -m pip install matplotlib==3.2
There seems to be an incompatibility issue using Matplotlib version 3.3 with IPython. For now, you can fix it by installing Matplotlib 3.2.
I had the same problem. I was using PyCharm. Installing PyQt5 worked for me.
I also had the same issue, and none of the above answers worked for me. After some trial and error, it seems that pyqt and qt were causing my issues. I know you are using venv, but if you don't mind using Anaconda, the following environment should work for you:
conda create -n matplotlib python==3.8.3 matplotlib==3.3.4 pyqt==5.9.2 qt==5.9.7
I tested this solution on python==3.8.3 and python==3.7.10 using Windows 10.
PySide2 is the official Qt (v5) for Python package which is officially supported by the Qt Company.
Install this module when using matplotlib and Jupyter/IPython
pip install pyside2
There is also PySide6 which is the package for Qt (v6)
Don't ask me why pyside2 is for qt5...
I reinstalled matplotlib to the latest version and it came out fine.
pip uninstall matplotlib
pip install matplotlib
This upgrades the matplotlib version from 3.3.4 to 3.4.2.
*I'm using python 3.7.6, windows, in a virtual environment.
I used to code in Jupyter notebook and importing pandas was never thrown an error. But when I use the same code in Visual Studio Code,
# Import Libraries
from random import seed
from random import randint
import pandas
import numpy
import math
import random
import collections
import itertools
import collections
import matplotlib.pyplot as plt
import seaborn as sns
# %matplotlib inline
I receive the below error.
File "g:/My Drive/M/importlibrary.py", line 5, in <module>
import pandas
File "C:\Users\M\Anaconda3\lib\site-packages\pandas\__init__.py", line 19, in <module>
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
I try to search for several similar issues and most of the solution ask to first uninstall and then install NumPy and Pandas using the below code,
pip3 uninstall pandas
pip3 uninstall numpy
However, I have followed this workaround but the problem did not resolve. The version of python that I am using is,
Python 3.6.8 :: Anaconda, Inc.
Please help if you can.
Is there a reason why you don't install Numpy/Pandas using anaconda (conda install -c anaconda numpy/pandas)? Did you run Jupyter from inside anaconda when it worked? I suggest going to terminal and figuring out where your modules are installed (i.e. if they are inside the anaconda folders, or somewhere where anaconda has access to).
In general, I'd advise against installing python packages for anaconda using pip, just use conda's package manager if you can. This question seems related. In your case, have you tried uninstalling the pip variant and reinstalling using conda?
The problem is resolved by uninstalling the Anaconda. I checked the control panel of the PC and found that there are multiple instances of python. VS Code uses Python 3.6.8 while Anaconda uses python 3.8. So, I uninstall 3.8, and then reinstall pandas,
pip3 uninstall pandas
pip3 install pandas
The error is no more.
Error Message:
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\__init__.py", line 17, in <modul> "Unable to required dependencies:\n" + "\n".join(missing_dependencies)
ImportError: Unable to import required dependencies:
numpy: DLL load failed
I did try re-installing numpy, pandas and mkl-services to no avail. Strangely, the code executes fine in Spyder, but simply won't run via "double-click" pointing towards C:\ProgramData\Anaconda3\python.exe
What am I doing wrong? Thanks!
Thanks to Yo_Chris I was able to solve my problem by de-/re-installing first pandas using pip and then doing the same for numpy.
pip uninstall pandas
pip install pandas
pip uninstall numpy
pip install numpy
As a note I did try those steps with conda before, but that did not solve the problem. I did think back then that conda and pip work the same. Apparently that is not the case.
Thanks again for letting me try pip!
I am running an Anaconda installation of Python3 64bit on Windows. I have no idea how to put those words in a proper sentence, but I hope it gives enough information. I am taking an Udacity course which wants me to run %matplotlib inline. This gives the following error:
AttributeError: module 'matplotlib' has no attribute 'colors'
I get the same error when I run from matplotlib import pylab, but i get no error from import matplotlib.
I installed matplotlib as follows: conda install -n tensorflow -c conda-forge matplotlib.
How do I solve this error?
Kind regards
Per request:
conda list gives
matplotlib 2.1.0 py36_1 conda-forge
and a list of other modules.
The notebook needs to be restarted for the new installations to take effect.
You just need to upgrade matplotlib.
pip3 install -U matplotlib