skip to Main Content

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


  1. Did you try checking the module name if it is calculation1 or calculation?

    Login or Signup to reply.
  2. 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 do import subdir.module. But in your case you have a module a level above, so you need to append that folder to the sys.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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search