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?

9
  • Place this 2 lines in the initial part of the file: import matplotlib matplotlib.use('Qt5Agg') Commented Aug 23, 2017 at 18:43
  • No luck - still getting the same error. Commented Aug 23, 2017 at 18:47
  • could show the code you are using and where you have placed what I suggested. Commented Aug 23, 2017 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 being asked here. Commented Aug 23, 2017 at 18:50
  • Your code should have the following form: import matplotlib matplotlib.use('Qt5Agg') import matplotlib.pyplot as plt Commented Aug 23, 2017 at 18:50

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.