ModuleNotFoundError: No module named 'module_name'

I am receiving the following error whenever I try to start a kedro jupyter notebook, or a KedroSession in the terminal. My project is called bri, and calling KedroSession.create(‘bri’) when in the top bri directory (th one containing conf, data, src etc.) gives the error:

I have no idea why this is happening - perhaps someone can explain how the line:

 from bri.hooks import ProjectHooks

in src/bri/settings.py knows how to use bri? This might help me understand it.

BTW I am using kedro 0.17.0

In fact, I have just created a fresh project with kedro 0.17.0, in a brand new conda environment. I did the following steps:

  • Create a new conda environment (python=3.8.5) and install kedro 0.17.0
  • run ‘kedro new’ to create a new project
  • run ‘kedro build-reqs’ and ‘kedro install’ to install the dependencies
  • run ‘kedro jupyter notebook’.

The result is the same error message, which is from the trace has a line:
settings = import_module(f"{package_name}.settings")

Clearly something is going wrong when trying to load the project settings?

UPDATE: I have figured out what the issue is! When load_context is called, it does the following check:

if "PYTHONPATH" not in os.environ:
    os.environ["PYTHONPATH"] = src_path

However, as my PYTHONPATH is not empty by default on my PC, the new path is not added to the PYTHONPATH at all, so load_context cannot find the project module.

Does anyone know why this check is here? Is there a reason why we need to check to see if the PYTHONPATH is empty - why not append to it if it already exists?

2 Likes