Python Forum

Full Version: Circular import dependency
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I got this message when trying to run my code:
Error:
ImportError: cannot import name 'convert_kernel' from partially initialized module 'keras.utils.conv_utils' (most likely due to a circular import) (/home/UbuntuUser/.local/lib/python3.8/site-packages/keras/utils/conv_utils.py)
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 qt
How I write it? What I do then?
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.
No, my fault. One of the issues that I try to solve is this line:
from PyQt5 import Qt as qt
The 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 QIcon
I deleted them and I wrote:
import PyQt5
But what I do when I have this?
from PyQt5 import Qt as qt
Do you understand my rationale?
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?
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.
@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/7336...-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?
(Feb-23-2021, 11:08 AM)hobbyist Wrote: [ -> ]when I import a file as something, how can I change this
when 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)
@buran: Can you please give me a code example in order to understand it?
Compare

import pandas
df = pandas.read_csv('some_file.csv') # here we use pandas
vs

import pandas as pd # we assign alias pd
df = pd.read_csv('some_file.csv') # here we use pd, not pandas
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.