I've installed two git submodules into my project. Those submodules contain a lot of relative imports, so if you just import something from them, they will not find necessary modules. This problem can be easily solved by adding following line before imports:
sys.path.insert(0, './yolov5_face') # where ./yolov5_face is path to submodule
But that solves problem only for one submodule. I have following project structure:
/yolov5 # submodule
/yolov5_face # submodule
detect_face.py # script, which imports yolov5_face
track.py # script, which imports yolov5
Submodules are almost identical but have slightly different classes and functions. Script detect_face.py gets loaded first, so I insert './yolov5_face' to sys.path before imports from submodule. Then, in trace.py I insert './yolov5' before imports. So my sys.path after second insertion looks that way:
['./yolov5', './yolov5_face', '/home/sher/Dev/realtime-detection', ... ]
And I have following error:
File "/home/sher/Dev/realtime-detection/track.py", line 14, in <module>
from yolov5.models.common import DetectMultiBackend
File "/home/sher/Dev/realtime-detection/yolov5/models/common.py", line 23, in <module>
from utils.datasets import exif_transpose, letterbox
ImportError: cannot import name 'exif_transpose' from 'utils.datasets' (/home/sher/Dev/realtime-detection/./yolov5_face/utils/datasets.py)
Function exif_transpose resides in yolov5 submodule and its path appears first in sys.path, but it seems like python searches for this import in yolov5_face instead. yolov5_face contains utils.datasets module too, but does not have exif_transpose function. Also all imports from detect_face.py loads just fine.
Is there a way to resolve this problem and use two submodules together?