Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pyplot import raises ImportError

I am having a strange problem tryin to import matplotlib. Whenever I do the import

import matplotlib.pyplot as plt

I get the following error message (When just importing matplotlib there is no error:

Vendor:  Continuum Analytics, Inc.
Package: mkl
Message: trial mode expires in 30 days
Traceback (most recent call last):
  File "C:\Users\Pierre\Anaconda3\lib\site-packages\matplotlib\backends\qt_compat.py", line 159, in <module>
    from PySide import QtCore, QtGui, __version__, __version_info__
ImportError: No module named 'PySide'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/Pierre/Dropbox/piR/Coding/Python/Eigene Projekte/GPX_reader/main.py", line 6, in <module>
    import matplotlib.pyplot as plt
  File "C:\Users\Pierre\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 114, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "C:\Users\Pierre\Anaconda3\lib\site-packages\matplotlib\backends\__init__.py", line 32, in pylab_setup
    globals(),locals(),[backend_name],0)
  File "C:\Users\Pierre\Anaconda3\lib\site-packages\matplotlib\backends\backend_qt4agg.py", line 18, in <module>
    from .backend_qt5agg import FigureCanvasQTAggBase as _FigureCanvasQTAggBase
  File "C:\Users\Pierre\Anaconda3\lib\site-packages\matplotlib\backends\backend_qt5agg.py", line 15, in <module>
    from .backend_qt5 import QtCore
  File "C:\Users\Pierre\Anaconda3\lib\site-packages\matplotlib\backends\backend_qt5.py", line 31, in <module>
    from .qt_compat import QtCore, QtGui, QtWidgets, _getSaveFileName, __version__
  File "C:\Users\Pierre\Anaconda3\lib\site-packages\matplotlib\backends\qt_compat.py", line 162, in <module>
    "Matplotlib qt-based backends require an external PyQt4, PyQt5,\n"
ImportError: Matplotlib qt-based backends require an external PyQt4, PyQt5,
or PySide package to be installed, but it was not found.

I use Python 3.5 in the Anaconda distribution on Windows 10. Anybody run into the same problem? The only recent change in the my setup was the (forced) upgrade to Windows 10...

Thanks and best wishes

Pierre

like image 853
pirwlan Avatar asked Apr 11 '16 19:04

pirwlan


1 Answers

You don't have PySide or PyQt installed, the Error Message is clear about that as matplotlib depends on either one of them

To install PySide run

pip install -U PySide

from the command line the -U stands for upgrade and means upgrade all packages you have installed to the newest version

from the man page of pip

-U, --upgrade
              Upgrade all packages to  the  newest  available  version.   This
              process  is  recursive  regardless  of  whether  a dependency is
              already satisfied.

but you should be just fine doing

pip install PySide

if for some reason you don't want to upgrade other packages installed by pip

like image 125
danidee Avatar answered Nov 07 '22 03:11

danidee