1

I am fairly new to python, and am having issues using PyQt5. Basically, i am trying to run the code i got from following this website (QtDesigner and PyQt5 basic tutorial), but am having issues:

https://nikolak.com/pyqt-qt-designer-getting-started/

I am using Python 3.6.1 on Windows with PyQt5. I am aware that the above tutorial uses Python 2 and PyQt4. I don't think that is part of the issue, but I could be wrong.

I try to run the main.py script from the above tutorial, and i get this error:

AttributeError: module 'PyQt5.QtGui' has no attribute 'QMainWindow'

because of line 6 in main.py. I assume that this is because PyQt5 is not properly installed, so I use pip:

pip install pyqt5

but get the following error:

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

I realize that some of the above main.py code will only work for pyqt4, I am just trying to get past the issue of not being able to correctly import PyQt5. Another program, that is made for PyQt5 and python 3.6, is having similar issues. When I try:

from PyQt5.QtWidgets import QMainWindow

I get this error back:

ImportError: cannot import name 'QMainWindow'

I have been trying to fix this issue for a while now, and have not found anything that has helped my situation thus far. Any help would be greatly appreciated, so that I can finally get this thing to work.

John M.
  • 11
  • 1
  • 3

1 Answers1

1
  1. Like Dan-Dev mentioned in the comments you should try "pip3 install pyqt5". If pip3 isn't being recognized that likely means it hasn't been added to the path. This link will help you find where your python directory is: How to install pip3 on Windows?. This link will help you add it to the path: https://www.java.com/en/download/help/path.xml

  2. In PyQt5 the QMainWindow is part of the QtWidgets library, so the first error you are getting is entirely expected.

  3. I'd recommend you take a look at some PyQt5 examples as the differences are minor but they will continue to trip you up while learning how to use PyQt. Take a look at this: Is there a tutorial specifically for PyQt5?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
aoh
  • 1,090
  • 2
  • 13
  • 25
  • I was able to get pip3 working, after following the instructions in step 1, but I am still getting the same error that I was getting using pip install pyqt5, that says no matching distribution found for pyqt5. I am not connected to the internet on the computer i am working on, and am not able to have it connected to the internet, and i think this could be a reason why. – John M. Jun 27 '17 at 00:48
  • That certainly can cause problems. You should also make sure that you have the latest version of pip3 installed and check out other questions like this [link](https://stackoverflow.com/questions/11091623/python-packages-offline-installation), then file a new and specific question if you run into issues with the installation process. – aoh Jun 27 '17 at 18:11