0
votes

I have upgraded my spyder to 4.0.1 , but now i get this error with matplotlib. The error:

AttributeError: module 'sip' has no attribute 'setapi'

complete error:

NOTE: The following error appeared when setting your Matplotlib backend!!

Traceback (most recent call last): File "C:\Users\premp\anaconda3\envs\tfcuda\lib\site-packages\spyder_kernels\console\kernel.py", line 568, in _set_mpl_backend get_ipython().run_line_magic(magic, backend) File "C:\Users\premp\anaconda3\envs\tfcuda\lib\site-packages\IPython\core\interactiveshell.py", line 2317, in run_line_magic result = fn(*args, **kwargs) File "", line 2, in matplotlib File "C:\Users\premp\anaconda3\envs\tfcuda\lib\site-packages\IPython\core\magic.py", line 187, in call = lambda f, *a, **k: f(*a, **k) File "C:\Users\premp\anaconda3\envs\tfcuda\lib\site-packages\IPython\core\magics\pylab.py", line 99, in matplotlib gui, backend = self.shell.enable_matplotlib(args.gui.lower() if isinstance(args.gui, str) else args.gui) File "C:\Users\premp\anaconda3\envs\tfcuda\lib\site-packages\IPython\core\interactiveshell.py", line 3419, in enable_matplotlib pt.activate_matplotlib(backend) File "C:\Users\premp\anaconda3\envs\tfcuda\lib\site-packages\IPython\core\pylabtools.py", line 320, in activate_matplotlib from matplotlib import pyplot as plt File "C:\Users\premp\anaconda3\envs\tfcuda\lib\site-packages\matplotlib\pyplot.py", line 2282, in switch_backend(rcParams["backend"]) File "C:\Users\premp\anaconda3\envs\tfcuda\lib\site-packages\matplotlib\pyplot.py", line 221, in switch_backend backend_mod = importlib.import_module(backend_name) File "C:\Users\premp\anaconda3\envs\tfcuda\lib\importlib__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "C:\Users\premp\anaconda3\envs\tfcuda\lib\site-packages\matplotlib\backends\backend_qt5agg.py", line 11, in from .backend_qt5 import ( File "C:\Users\premp\anaconda3\envs\tfcuda\lib\site-packages\matplotlib\backends\backend_qt5.py", line 15, in import matplotlib.backends.qt_editor.figureoptions as figureoptions File "C:\Users\premp\anaconda3\envs\tfcuda\lib\site-packages\matplotlib\backends\qt_editor\figureoptions.py", line 12, in from matplotlib.backends.qt_compat import QtGui File "C:\Users\premp\anaconda3\envs\tfcuda\lib\site-packages\matplotlib\backends\qt_compat.py", line 163, in _setup() File "C:\Users\premp\anaconda3\envs\tfcuda\lib\site-packages\matplotlib\backends\qt_compat.py", line 124, in _setup_pyqt4 _setup_pyqt4_internal(api=2) File "C:\Users\premp\anaconda3\envs\tfcuda\lib\site-packages\matplotlib\backends\qt_compat.py", line 107, in _setup_pyqt4_internal sip.setapi(_sip_api, api) AttributeError: module 'sip' has no attribute 'setapi'

Currently i have matplotlib 3.2.1 , i have tried downgrading and also tried changing the setting from automatic to inline. But not able to figure out the issue. Is this a bug?

2

2 Answers

2
votes

As I understand you are running your command in a virtual environment.

I had similar issue with matplotlib 3.3.2, on windows 10, when running the command on my virtual environment:

(base) (venv) C:\Users\Samtha\Documents\automation_tool>python -c "import matplotlib.pyplot as plt"

It gave AttributeError: module 'sip' has no attribute 'setapi'.

Tried the mentioned solution here: enter link description here

(base) (venv) C:\Users\Samtha\Documents\automation_tool> python -c "import matplotlib;matplotlib.use('TkAgg');import matplotlib.pyplot as plt"

and it works now.

1
votes

I had a similar problem and fixed it by adding the sip module to my anaconda environment.