Circular import dependency - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Circular import dependency (/thread-32637.html) |
Circular import dependency - hobbyist - Feb-23-2021 Hello, I got this message when trying to run my code: After searching I found that this has to do with how I import the packages on the code. And I have fixed many of them, but what do I do, when I have situation like this:from PyQt5 import Qt as qtHow I write it? What I do then? RE: Circular import dependency - Gribouillis - Feb-23-2021 It is hard to believe that importing PyQt5 tries to import anything from keras. There must be some missing information in your description of the issue. RE: Circular import dependency - hobbyist - Feb-23-2021 No, my fault. One of the issues that I try to solve is this line: from PyQt5 import Qt as qtThe other lines, such as (there are many lines I try to fix, with keras or not) these: from PyQt5.QwIdgets import QMainWindow from PyQt5.QtGui import QIconI deleted them and I wrote: import PyQt5But what I do when I have this? from PyQt5 import Qt as qtDo you understand my rationale? RE: Circular import dependency - Gribouillis - Feb-23-2021 I don't really understand. When you replace from PyQt5.QwIdgets import QMainWindow by import PyQt5 , then what do you do when the code uses the name QMainWindow ? Also, why do that?
RE: Circular import dependency - buran - Feb-23-2021 Please, post minimal reproducible example and full traceback that you get with the code you post. As @Gribouillis already mentioned the error in the first post has nothing to do with PyQt. Also it's unclear what you want to do with imports as described in post #3 and how you use the names imported. RE: Circular import dependency - hobbyist - Feb-23-2021 @Gribouillis: I haven't run correctly the code yet, I try to change every line to be consistent with not being Circular import dependent, and I go line-by-line, following this post here: https://stackoverflow.com/questions/7336802/how-to-avoid-circular-imports-in-python and when I try to execute the code eventually does not display errors on these lines BUT I have no idea what to do with this point here from PyQt5 import Qt as qt. What I mean is when I import a file as something, how can I change this? RE: Circular import dependency - buran - Feb-23-2021 (Feb-23-2021, 11:08 AM)hobbyist Wrote: when I import a file as something, how can I change thiswhen you use as you define alias. So in this case you import Qt from PyQt5 under alias qt . Instead of using name Qt you will use name qt (i.e. the alias)
RE: Circular import dependency - hobbyist - Feb-23-2021 @buran: Can you please give me a code example in order to understand it? RE: Circular import dependency - buran - Feb-23-2021 Compare import pandas df = pandas.read_csv('some_file.csv') # here we use pandasvs import pandas as pd # we assign alias pd df = pd.read_csv('some_file.csv') # here we use pd, not pandas RE: Circular import dependency - Gribouillis - Feb-23-2021 The line from PyQt5 import Qt as qt cannot take part in a circular import, unless you define another PyQt5 module of your own. You can leave it alone. If you have circular import issues, my advice is to concentrate on these specific circular imports.
|