NameError: name 'Qt' is not defined
-
wrote on 23 Feb 2021, 20:30 last edited by john_hobbyist
Hello I am searching for circular imports in my code and I try to avoid them and debug the code but I face this error:
File "code.py", line 535, in __init__ sharedLayout.setAlignment(Qt.AlignTop | Qt.AlignLeft) NameError: name 'Qt' is not defined
I have imported PyQt5...What is this?
-
Hi,
If you did just:
import PyQt5
Then it won't be able to find the Qt namespace because you only made the PyQt5 namespace available.
-
wrote on 23 Feb 2021, 20:34 last edited by
Yes but if I write
from...import....
I get circular imports! What should I do?
-
Use the fully qualified name.
How do you create circular imports by using PyQt5 ?
-
wrote on 23 Feb 2021, 20:38 last edited by
This is what I am trying to find out. What is the command of what you are writing?
-
Yes but if I write
from...import....
I get circular imports! What should I do?
wrote on 23 Feb 2021, 20:42 last edited by JonB@john_hobbyist
Which circular imports where?You can do this from PyQt5:
from PyQt5.QtCore import Qt
and then your original code should work.
In fairness, it is a bit complicated. https://stackoverflow.com/questions/39316693/how-to-import-from-qt-namespase-qt5-python3-x, the solution there, describes the situation and why this works, if you care.
-
PyQt5.QtCore.Qt.Whatever
Or more simply:
from PyQt5.QtCore import Qt
and then use Qt.
-
wrote on 23 Feb 2021, 20:50 last edited by john_hobbyist
Amazing! It works!!! Thanks a lot for your time!
-
Amazing! It works!!! Thanks a lot for your time!
wrote on 24 Feb 2021, 12:47 last edited by@john_hobbyist said in NameError: name 'Qt' is not defined:
It works!!!
so please don't forget to mark your post as solved!
-
wrote on 10 Feb 2025, 09:15 last edited by
Detail ModuleNotFoundError: No module named 'PyQt5' im still facing this issue
-
Detail ModuleNotFoundError: No module named 'PyQt5' im still facing this issue
@sneha_chavan_07 Then please provide more information. Did you install PyQt5 and how? On which OS?