Let me start off by saying I know this issue has already been discussed, but I could not find a solution that was similar to my case.
I have a directory structure like the following:
- project/
- tools
- my_tool
- tool_name.py
- my_tool
- tests
- lib
- constants.py
- my_test.py
- common/
- check_lib.py
- lib
- tools
I need to import constants.py, check_lib.py, and tool_name.py into my_test.py using relative paths. Is there a way to do this even though several of my modules are in various depths within different directories in my project? I am trying to do this directly in the code with a "from module.path import module" type of import. Any help is greatly appreciated!
MY solution was the following:
tool_name.py
print("tool_name.py imported")
constants.py
print("constants.py imported")
check_lib.py
print("check_lib.py imported")
my_test.py
import constants
import common.check_libimport sys
import os
sys.path.append(os.path.abspath('test_project/tools/my_tool'))import tool_name
output :
constants.py imported
check_lib.py imported
tool_name.py imported
my_test.py is running