Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Circular import dependency
#1
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?
Reply
#2
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.
Reply
#3
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?
Reply
#4
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?
Reply
#5
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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#6
@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?
Reply
#7
(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)
hobbyist likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#8
@buran: Can you please give me a code example in order to understand it?
Reply
#9
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
hobbyist likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#10
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.
buran and hobbyist like this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Poetry Dependency general Help felipesodre 0 131 Jan-14-2021, 07:46 PM
Last Post: felipesodre
  Installing nltk dependency Eshwar 0 315 Aug-30-2020, 06:10 PM
Last Post: Eshwar
  How do I change wx version dependency? belfacode 0 357 May-17-2020, 09:18 AM
Last Post: belfacode
  Module Dependency installation error draems 10 5,140 Feb-12-2017, 08:18 AM
Last Post: wavic
  Robot Stay Inside Circular Ring webmanoffesto 4 3,582 Dec-07-2016, 06:57 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020