I want to understand the root of my problem. I have encountered this a couple times and it is quite time consuming to figure it out each time.
This time I feel like I have missed something that I thought I understood. A related question is posted here: Infinite loop with Python imports; looking for Pythonic way
I decided my modules present an infinite loop, but I still get the same error. so here are what I have.
I have included __init__.py
files here too because I suspect that this file might cause behavior that I am currently unaware of.
In sources/preparation/features/__Init__.py
:
from .build_features import *
from .get_qualified_edges import *
from .select_strategy import *
from .test import *
In sources/preprocessing/__init__.py
, I have:
from .apply_preprocessing import *
from .convertion import *
In sources/preprocessing/apply_preprocessing
I have:
from Sources.Preparation.Features.get_qualified_edges import get_all_GeneDisease_unweighted_disease2disease_qualified_edges
from Sources.Preparation.Features.get_qualified_edges import get_GPSim_disease2disease_qualified_edgesjk
In directory source/preparation/features/get_qualified_edges.py
:
from Sources.Preprocessing.convertion import Converter # added this lien causes error to be raised
from itertools import combinations
In Sources/preprocessing/conversion.py
I don't have anything imported.
Below are the sequence of files that are run because error arise:
sources\__init__.py
sources\preparation\__init__.py
sources\prepartion\features\__init__.py
sources\preparation\features\build_features.py
sources\preparation\features\get_qualified_edgdes.py
sources\preprocessing\__init__.py
sources\preprocessing\apply_preprocessing.py
\\error raise
The error is raised when I import a class from Sources.Preprocessing.convertion
as shown below. In source/preparation/features/get_qualified_edges.py
:
from Sources.Preprocessing.convertion import Converter # added this lien causes error to be raised
Let me know if you folks need more information about this problem.
What I want to know is: Why does this problem occur?
I solved the problem when I moved Converter
from Sources.Preprocessing.convertion
to Sources.Preparation.Data.conversion
.
Observation
What I observed is that the error disappeared when there are no "cross" imports between Sources.Preprocessing.modules_A
(imported in Sources.Preparation.modules_C
) and Sources.Preparation.modules_B
(imported in Sources.Preprocessing.modules_D
).
That's it. There are no direct "cross" imports between modules and instead there are "cross" imports between parent modules, if that makes any sense.