1

I'm having issues import matplotlib.pyplot. I recently updated to Python 3.5.2. The error it gives me is as such:

ImportError: Matplotlib qt-based backends require an external PyQt4, PyQt5, or PySide package to be installed, but it was not found.

So I install PyQt5 using pip install pyqt5, and I successfully install it. I run my code again, and then I get a different error:

ImportError: No module named 'PyQt4'

So I use pip (pip install pyqt4) and attempt to install it. I get another error saying that PyQt4 can not be installed in the command prompt:

(User) C:\Users\Username>pip install pyqt4

Collecting pyqt4

Could not find a version that satisfies the requirement pyqt4 (from versions: ) No matching distribution found for pyqt4

So my question is, is what do I need to do to be able to import this package?

Brandon Molyneaux
  • 1,543
  • 2
  • 12
  • 23
  • Place this 2 lines in the initial part of the file: `import matplotlib` `matplotlib.use('Qt5Agg')` – eyllanesc Aug 23 '17 at 18:43
  • No luck - still getting the same error. – Brandon Molyneaux Aug 23 '17 at 18:47
  • could show the code you are using and where you have placed what I suggested. – eyllanesc Aug 23 '17 at 18:49
  • If you have pyqt5 installed, you don't need pyqt4 for running matplotlib. It will require either of them, not both. I'm not sure but I think installing pyqt4 for python3 is not straight forward, so don't dive into this if you don't have to. There is also a [similar question](https://stackoverflow.com/questions/44051058/pyqt5-gets-no-module-named-pyqt4-error-calling-matplotlib-pyplot-in-python-3?rq=1) being asked here. – ImportanceOfBeingErnest Aug 23 '17 at 18:50
  • Your code should have the following form: `import matplotlib` `matplotlib.use('Qt5Agg')` `import matplotlib.pyplot as plt` – eyllanesc Aug 23 '17 at 18:50
  • `import matplotlib` `matplotlib.use(Qt5Agg')` `import matplotlib.pyplot as plt` – Brandon Molyneaux Aug 23 '17 at 18:50
  • @ImportanceOfBeingErnest those were my exact thoughts - why would I have to install PyQt4 if I have installed PyQt5 installed? The link you posted is the exact problem I'm having. – Brandon Molyneaux Aug 23 '17 at 18:59
  • So did you try any of the solutions there? Even if they fail, the information about what you tried are usefull for others to further help. – ImportanceOfBeingErnest Aug 23 '17 at 19:07
  • I did try the solutions that were suggested, but to no avail. Hopefully it works for someone else! – Brandon Molyneaux Aug 23 '17 at 21:24

1 Answers1

0

I had to install PyQt4, even though I have PyQt5. Using

import matplotlib
matplotlib.use('Qt5Agg')
import matplotlib.pyplot as plt

did not work in my case.

Brandon Molyneaux
  • 1,543
  • 2
  • 12
  • 23
  • Same for me. Neither Pyside, Pyside2 or PyQt5 worked. I installed PyQt4 with the package manager, `sudo apt-get install python3-pyqt4` and it worked. – Benares Jul 12 '18 at 22:45