I have made a project tree:
.
├── calculations
│ ├── calculation1.py
│ └── calculation2.py
| └── __init__.py
├── final_combinations
│ ├── project.py
│ └── non_project.py
In project.py
I import the calculations from calculations folder:
from calculations.calculation1 import calculation1
from calculations.calculation2 import calculation2
def project():
x = calculation1(13) + calculation2(15)
return x
This works on my PC well, but when my colleague run this codes after pulling from my repo it gives error ModuleNotFoundError: No module named "calculations"
. In his computer he has added python to his PATH. We use Visual Studio Code and have same settings. File is uploaded to Databricks and run on it using VSCode plug-in databricks-connect.
2
Answers
Did you try checking the module name if it is calculation1 or calculation?
This is a "known" behavior when workspace files are used. By default, only the current folder of the file is added to the
sys.path
, so if you have a subdirectory, you can doimport subdir.module
. But in your case you have a module a level above, so you need to append that folder to thesys.path
to be discoverable – it’s covered in the documentation.Alternatively, you can use Repos that have a bit different behavior – the
sys.path
is populated not only with the current directory, but also with the root of the repository.