2

I have connected a Github repository to my Databricks workspace, and am trying to import a module that's in this repo into a notebook also within the repo. The structure is as such:

Repo_Name

  • Checks.py
  • Test.ipynb

The path to this repo is in my sys.path(), yet I still get ModuleNotFoundError: No module named 'Checks'. When I try to do import Checks. This link explains that you should be able to import any modules that are in the PATH. Does anyone know why it might still not be working?

Alex Ott
  • 80,552
  • 8
  • 87
  • 132
MKJ
  • 120
  • 8

2 Answers2

1
  • I have tried doing the same and got a similar error even after following the procedure as given in the link provided in the question.
  • I have the following python files in my GIT repo (3 files with .py extension).

enter image description here

  • Now when I add the path /Workspace/Repos/<username>/repro0812 to sys.path and try to import the sample module from this repo, it throws the same error.

enter image description here

  • This is because, for some reason, this file is not being rendered as a python file. When I open the repo, you can actually see the difference.

enter image description here

  • There was no problem while I import the other 2 python modules check and sample2. The following is an image for refernce.

enter image description here

  • Check and make sure that the file is being considered as a .py file after adding your repo.
Saideep Arikontham
  • 5,558
  • 2
  • 3
  • 11
  • Unfortunately, this also isn't the issue for me. All files are in the repo with the .py extension. The notebook in which I'm trying to import them is also in the repo, but the location of it shouldn't matter as long as I add the repo path to my PATH right? – MKJ Dec 13 '22 at 08:00
  • Yes, when the file can be seen as `.py` file in your databricks workspace Repo and the path is added to `sys.path`, you should have no problem in importing the module. – Saideep Arikontham Dec 13 '22 at 08:06
  • Yet it still doesn't work :/. – MKJ Dec 13 '22 at 08:27
1

Most probably your .py file is a notebook, not a Python file. Notebooks couldn't be imported as Python modules, only Python files could be used in this case.

You can check if this .py has the following text in the first line:

# Databricks notebook source

If it contains, you can remove this line, and file will be considered as Python file, not as a notebook.

Alex Ott
  • 80,552
  • 8
  • 87
  • 132