matplotlib - module 'sip' has no attribute 'setapi'

Viewed 15567

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.

6 Answers

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