cancel
Showing results for 
Search instead for 
Did you mean: 
Get Started Discussions
Start your journey with Databricks by joining discussions on getting started guides, tutorials, and introductory topics. Connect with beginners and experts alike to kickstart your Databricks experience.
cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot import editable installed module in notebook

newenglander
New Contributor II

Hi,

I have the following directory structure:

- mypkg/
  - setup.py
  - mypkg/
    - __init__.py
    - module.py
- scripts/
  - main # notebook
  

From the `main` notebok I have a cell that runs:

%pip install -e /path/to/mypkg

This command appears to successfully install the package. And in a subsequent cell I can run:

!python -m mypkg.module

and it executes successfully.

However, when I try in a notebook cell to simply run:

import mypkg.module

the execution fails with the message: 

ModuleNotFoundError: No module named 'mypkg'

I've tried executing the import both before and after running `%restart_python` and it fails either way.

Please advise.

Thank you

2 REPLIES 2

Louis_Frolio
Databricks Employee
Databricks Employee

Hey @newenglander — always great to meet a fellow New Englander 😊

Could you share a bit more detail about your setup? For example, are you running on classic compute or serverless? And are you working in a customer workspace, or using Databricks Free Edition (formerly Community Edition)?

Any additional context you can provide will help me point you in the right direction.

Cheers, Louis.

This issue happens because Jupyter uses a different Python environment from the one where you installed mypkg in editable mode. Although running
%pip install -e /path/to/mypkg inside the notebook prints a success message, that command may run in a separate interpreter than the one your active notebook kernel uses.

When you later execute !python -m mypkg.module, it works only because !python launches an external process that uses your system or virtualenv Python — not the running Jupyter kernel’s Python session.​

Confirm what’s happening

To verify the mismatch:

python
import sys print(sys.executable) !which python !jupyter kernelspec list

If these point to different paths, that’s the cause of your ModuleNotFoundError.

Solutions

1. Ensure your notebook kernel uses the same environment

Activate the same environment you used for the editable install and register it as a Jupyter kernel:

bash
source /path/to/venv/bin/activate pip install ipykernel python -m ipykernel install --user --name mypkg-env --display-name "mypkg env"

Then reopen your notebook and select “mypkg env” from the kernel list.​

2. Verify installation path

In a notebook cell, print out:

python
import site site.getsitepackages()

Check that the editable-path .egg-link file for mypkg is in one of these directories.

3. As a fallback, add it to sys.path manually

If switching kernels is not possible, append the install location:

python
import sys sys.path.append("/path/to/mypkg") import mypkg.module

This mirrors what happens automatically in the terminal’s sys.path but not in Jupyter’s environment.​

4. Optionally reinstall inside the notebook’s environment

If you confirm that the notebook uses a different environment (e.g., Conda base or system Python), reinstall mypkg inside it:

python
%pip install -e /path/to/mypkg --force-reinstall

Once the kernel and Jupyter runtime point to the same Python interpreter where the editable installation resides, import mypkg.module will succeed consistently.

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!

Sign Up Now