matplotlib - module 'sip' has no attribute 'setapi'
Asked Answered
P

6

23

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.

Pandanus answered 10/10, 2020 at 7:33 Comment(0)
D
10

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.

Disenfranchise answered 16/10, 2020 at 16:17 Comment(4)
Thanks for the suggestion. According to another post, the Anaconda distribution does not include support for Python 3.2 https://mcmap.net/q/584706/-python-3-2-in-anacondaPandanus
I meant Matplotlib version 3.2 not Python 3.2. I edited the answer to clear that up.Disenfranchise
for me matplotlib==3.3.4, downgrade the matplotlib to 3.2, it workedTether
For reference, I also get this issue on VSCode, but when using Spyder in the same anaconda environment %matplotlib qt5 works fine. So it's not a pure ipython issue, but something in the way ipython and VSCode work together.Assortment
W
29

This worked for me.

python -m pip install matplotlib==3.2
Whitman answered 18/10, 2020 at 18:47 Comment(1)
i found the same issue. this was due to the different version. This solved my issue. Thanks @nunoCoessential
D
10

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.

Disenfranchise answered 16/10, 2020 at 16:17 Comment(4)
Thanks for the suggestion. According to another post, the Anaconda distribution does not include support for Python 3.2 https://mcmap.net/q/584706/-python-3-2-in-anacondaPandanus
I meant Matplotlib version 3.2 not Python 3.2. I edited the answer to clear that up.Disenfranchise
for me matplotlib==3.3.4, downgrade the matplotlib to 3.2, it workedTether
For reference, I also get this issue on VSCode, but when using Spyder in the same anaconda environment %matplotlib qt5 works fine. So it's not a pure ipython issue, but something in the way ipython and VSCode work together.Assortment
L
9

I had the same problem. I was using PyCharm. Installing PyQt5 worked for me.

Larval answered 24/11, 2020 at 6:31 Comment(1)
pip install PyQt5 - worked for me. Win10. Matplotlib 3.4.1, Py 3.8.5.Works
M
2

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.

Mccaleb answered 9/3, 2021 at 17:27 Comment(0)
A
1

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...

Aerodonetics answered 22/3, 2021 at 1:59 Comment(0)
M
1

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.

Malemute answered 22/5, 2021 at 6:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.