Circular Import Error With Some Not Familar Error
Solution 1:
can you please share your contents inside requirements.txt and what all libraries are being imported in project Black-Lightning. This issue seems to be an issue of circular import. I will try to give you an overview of what circular import is and the way you can avoid or debug this in your code.
Circular import occurs when two modules depend on each other. Let's say you have two modules ( can be from the external libraries you use or from your codebase ) and they look like below: -
# module1import module2
deffunction1():
module2.function2()
deffunction3():
print('Goodbye, World!')
# module2import module1
deffunction2():
print('Hello, World!')
module1.function3()
Let's say that you have a init.py that is calling module1.function1(), in this case, what is gonna happen is that while calling function1(), it will see that a function from module2 is being called named as function2(). So it will import that come to function2(). But remember python hasn't reached function3() of module1. So when function3() of module1 is being called from function2() of module1, it throws an error.
This is an instance of circular import because of the modules present inside your code. It is possible to have the same scenarios while using different versions of different libraries.
To avoid this kind of problem, I will suggest two things strongly: -
NEVER try to have imports like "from xyz import *"
If you have multiple modules inside your code try to mention the exact path while importing them. DON'T :-> from xyz import a, b, c
DO :-> from <MODULE_PATH>/xyz import a, b, c
To debug the issue for Circular import, you can try using Module Finder. This can help you list down all the dependencies from your project then you can go through and see which ones are conflicting
Another obvious way to debug this issue is by running your application in verbose mode by using a command similar to python -v <script_name>.py
Hopefully, these steps might help you resolve your issues. Please reach out in the comments if any other clarifications required.
Reference:- Python Circular Imports
Post a Comment for "Circular Import Error With Some Not Familar Error"