I have a python script that is calling a module from another python project, whose path is correctly included in sys.path, however the script returns error "module not found".
More in detail, this is the following structure:
/home/lbri/sdfstudio/script.py --> the main script that I am running
/home/lbri/omnidata/omnidata_tools/torch/data/transforms.py --> the module that I am trying to call from script.py
These are the relevant lines inside script.py:
sys.path.append(args.omnidata_path)
print(sys.path)
from data.transforms import get_transform
which is run with
python script.py --omnidata-path /home/lbri/omnidata/omnidata_tools/torch/
This is the error that I get:
['/home/lbri/sdfstudio/scripts/datasets', '/home/lbri/miniconda3/envs/sdfstudio/lib/python38.zip', '/home/lbri/miniconda3/envs/sdfstudio/lib/python3.8', '/home/lbri/miniconda3/envs/sdfstudio/lib/python3.8/lib-dynload', '/home/lbri/miniconda3/envs/sdfstudio/lib/python3.8/site-packages', '__editable__.nerfstudio-0.1.12.finder.__path_hook__', '/home/lbri/omnidata/omnidata_tools/torch/']
Traceback (most recent call last):
File "script.py", line 41, in <module>
from data.transforms import get_transform
ModuleNotFoundError: No module named 'data.transforms'
I don't understand: the path of the module ('/home/lbri/omnidata/omnidata_tools/torch/') is included correctly in sys.path, yet the script does not see the module. Am I missing something obvious?
I also tried to put some init.py files inside the folders containing the module, but nothing changes.
Thank you!
EDIT: I also tried to include /home/lbri/omnidata/omnidata_tools/torch/data/ into the sys.path as well, but I still get the same error.
ok, posting the answer to my question, with a bit of delay.
Basically the main problem is that 'data' and 'torch' are too generic names - which are already used by the script to indicate different modules.
Therefore, the solution was:
/home/lbri/omnidata/omnidata_tools
in the syspathfrom omnidata_tools.torch.data.transforms import get_transform
Then everything works fine.