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.
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 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.
I installed Python 3 on MacOS Mojavie 10.14 using:
brew install python3
Then using the following command I installed matplotlib
pip3 install matplotlib
Importing matplotlib.pyplot is successful on Python 2:
Python2 screenshot
but fails on Python 3:
Python3 screenshot
I have tried reinstalling python3 and matplotlib but failed. Could not find a solution.
This is a bug in matplotlib 3.0.0,
https://github.com/matplotlib/matplotlib/issues/12173
https://github.com/matplotlib/matplotlib/issues/12439
which will be fixed in an upcoming 3.0.1 release.
https://github.com/matplotlib/matplotlib/pull/12213
In lib/matplotlib/font_manager.py:
Alternatively, downgrade to matplotlib 2.2.3 until 3.0.1 is released.
I am anaconda on a mac os x Yosemite, running python 3.5. I used the following command from anaconda's website
conda install -c menpo opencv3=3.1.0
The terminal read out nothing to do with opencv2.
However, in the ipython console I am unable to import cv3. I get,
conda install -c menpo opencv3=3.1.0
Yet.... interestingly enough I able import cv2. I have read a bit that opencv can be a tricky and wily beast to get working...
Also anaconda specifically says that I have only the opencv3 package.
So, I am wondering... even though I am using opencv3 maybe for some reason it still uses cv2 as the package name to import?
Thanks for any insight!
Apparently, it is just that simple... import cv2 even if you have opencv3.x.
Thank you Miki.
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.