'Can't import uic from PyQt5
I am trying to load my .ui file in python and i want to use uic.loadUI() function but I have problem with importing it, I get an error:
*Cannot find reference 'uic' in '__init__.pyi'*
My code:
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5 import uic
import sys
class UI(QWidget):
def __init__(self):
super().__init__()
uic.loadUi("mybutton.ui", self)
app = QApplication([])
window = UI()
window.show()
app.exec_()
I am using python 3.9.7. Installed PyQt5 with pip. Checked the PyQt5 folder and it looks like this: https://i.stack.imgur.com/bTlXs.png
Can You please help?
Solution 1:[1]
I had a simular problem when using PyCharm. The following Code fixed the issue:
from PyQt5.uic import loadUiType
from os import path
FORM_CLASS, _ = loadUiType(path.join(path.dirname(__file__), "mybutton.ui"))
I Think its a Bug from PyCharm
Solution 2:[2]
Filip where do put the FORM_CLASS, _ = loadUiType(path.join(path.dirname(file), "mybutton.ui"))
Solution 3:[3]
loadUi(path.join(path.dirname(file), "w.ui"),self)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Philipp1297 |
| Solution 2 | Russell Murphy |
| Solution 3 | user17057121 |
