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

Your error is from here:

Ui_Widget(QtGui.QWidget)

It basically tells you what the problem is.

It seems you are mixing some QT4 and QT5 here as your import is in QT5-style, but QtGui.QWidget looks like QT4-style.

Replace the line with:

Ui_Widget(QtWidgets.QWidget)

which should be compatible according to the docs

Remark: I don't know what you are really doing, but when you mention this: Even when I change class Ui_Widget(QtGui.QWidget): to class Ui_Widget(QtGui.QtWidgets): I get AttributeError: module 'PyQt5.QtGui' has no attribute 'QtWidgets' That's correct. You already imported QtWidgets, and not from PyQt5.QtGui. Just use Ui_Widget(QtWidgets) there.

In short: all these errors seem to be related to refactoring in regards to the modules between QT4 and QT5. The docs should help.