question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[KED-2373] ModuleNotFound when loading kedro context with 0.17

See original GitHub issue

Description

Hello, I have faced an error while upgrading to Kedro 0.17 with the kedro context. I am able to use kedro ipython to start a Kedro session, with the context variable loaded. However, if I try and load the context directly from ipython using

from kedro.framework.context import load_context
context = load_context(proj_path)

I get an error. I have also tried using the new KedroSession, and I get the same error. I have also tried running the .ipython/profile_default/startup/00-kedro-init.py script and get the same error (see below).

Expected Result

I should be able to load the context, in order to use commands like context.io.load("")

Actual Result

I am getting a ModuleNotFoundError with the name of my package. The error I get when I use from kedro.framework.context import load_context:

/Users/jeffreykayne/Documents/Clients/Econocom/econocom-ccai/ds/venv/lib/python3.7/site-packages/kedro/framework/context/context.py:666: DeprecationWarning: `kedro.framework.context.load_context` is now deprecated in favour of `KedroSession.load_context` and will be removed in Kedro 0.18.0.
  DeprecationWarning,
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-7-82df189e622a> in <module>
      1 proj_path = Path.cwd()
----> 2 context = load_context(proj_path)

~/Documents/Clients/Econocom/econocom-ccai/ds/venv/lib/python3.7/site-packages/kedro/framework/context/context.py in load_context(project_path, **kwargs)
    670 
    671     context_class = _get_project_settings(
--> 672         metadata.package_name, "CONTEXT_CLASS", KedroContext
    673     )
    674 

~/Documents/Clients/Econocom/econocom-ccai/ds/venv/lib/python3.7/site-packages/kedro/framework/project/settings.py in _get_project_settings(package_name, property_name, default)
     34     package_name: str, property_name: str, default: Any = None
     35 ) -> Any:
---> 36     settings = import_module(f"{package_name}.settings")
     37     return getattr(settings, property_name, default)

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py in import_module(name, package)
    125                 break
    126             level += 1
--> 127     return _bootstrap._gcd_import(name[level:], package, level)
    128 
    129 

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _gcd_import(name, package, level)

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _find_and_load(name, import_)

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _gcd_import(name, package, level)

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _find_and_load(name, import_)

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

ModuleNotFoundError: No module named 'ds'

The error I get when I use from kedro.framework.session import KedroSession:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-12-dac7a85b2eb6> in <module>
      4 
      5 metadata = _get_project_metadata("/Users/jeffreykayne/Documents/Clients/Econocom/econocom-ccai/ds")
----> 6 session = KedroSession.create(metadata.package_name, "/Users/jeffreykayne/Documents/Clients/Econocom/econocom-ccai/ds")

~/Documents/Clients/Econocom/econocom-ccai/ds/venv/lib/python3.7/site-packages/kedro/framework/session/session.py in create(cls, package_name, project_path, save_on_close, env, extra_params)
    199             project_path=project_path,
    200             session_id=generate_timestamp(),
--> 201             save_on_close=save_on_close,
    202         )
    203 

~/Documents/Clients/Econocom/econocom-ccai/ds/venv/lib/python3.7/site-packages/kedro/framework/session/session.py in __init__(self, session_id, package_name, project_path, save_on_close)
    167         self.save_on_close = save_on_close
    168         self._package_name = package_name
--> 169         self._store = self._init_store()
    170 
    171     @classmethod

~/Documents/Clients/Econocom/econocom-ccai/ds/venv/lib/python3.7/site-packages/kedro/framework/session/session.py in _init_store(self)
    247     def _init_store(self) -> BaseSessionStore:
    248         store_class = _get_project_settings(
--> 249             self._package_name, "SESSION_STORE_CLASS", BaseSessionStore
    250         )
    251         classpath = f"{store_class.__module__}.{store_class.__qualname__}"

~/Documents/Clients/Econocom/econocom-ccai/ds/venv/lib/python3.7/site-packages/kedro/framework/project/settings.py in _get_project_settings(package_name, property_name, default)
     34     package_name: str, property_name: str, default: Any = None
     35 ) -> Any:
---> 36     settings = import_module(f"{package_name}.settings")
     37     return getattr(settings, property_name, default)

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py in import_module(name, package)
    125                 break
    126             level += 1
--> 127     return _bootstrap._gcd_import(name[level:], package, level)
    128 
    129 

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _gcd_import(name, package, level)

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _find_and_load(name, import_)

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _gcd_import(name, package, level)

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _find_and_load(name, import_)

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

ModuleNotFoundError: No module named 'ds'

Your Environment

  • Kedro version used (pip show kedro or kedro -V):
Name: kedro
Version: 0.17.0
Summary: Kedro helps you build production-ready data and analytics pipelines
Home-page: https://github.com/quantumblacklabs/kedro
Author: QuantumBlack Labs
Author-email: None
License: Apache Software License (Apache 2.0)
Location: /Users/jeffreykayne/Documents/Clients/Econocom/econocom-ccai/ds/venv/lib/python3.7/site-packages
Requires: setuptools, cachetools, fsspec, PyYAML, python-json-logger, gitpython, click, pluggy, toml, jupyter-client, pip-tools, toposort, cookiecutter, jmespath, anyconfig
Required-by: 
  • Python version used (python -V):
Python 3.7.9

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
lorenabalancommented, Jan 12, 2021

@jeffkayne

I’m looking into it, it might a use case we overlooked, but let me confirm. As a workaround in the meantime you can add the following snippet in your notebook before running load_context:

from kedro.framework.cli.utils import _add_src_to_path

_add_src_to_path(Path.cwd()/"src", Path.cwd())

Assuming your source directory is called “src” and Path.cwd() is path to the root of the project (feel free to adapt accordingly).

@sansagara @nagendratekuri

I think I know what your issue is, but it’s not a bug - it’s a feature we’ve been slowly introducing since 0.16.5. We’re moving things away from the context. If you’re using the TemplatedConfigLoader, the way to use it is via register_config_loader hook in hooks.py, as opposed to overriding the function ProjectContext._create_config_loader. In fact ProjectContext should eventually go away entirely, unless needed for very complex customisations.

See our migration guide.

  • Copy changes made to ConfigLoader. If you have defined a custom class, such as TemplatedConfigLoader, by overriding ProjectContext._create_config_loader, you should move the contents of the function in src/<package_name>/hooks.py, under register_config_loader.
2reactions
sansagaracommented, Jan 15, 2021

Indeed @lorenabalan That was the issue!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

[KED-2373] ModuleNotFound when loading kedro context ...
Description Hello, I have faced an error while upgrading to Kedro 0.17 with the kedro context. I am able to use kedro ipython...
Read more >
kedro.framework.context — Kedro 0.17.7 documentation
kedro.framework.context provides functionality for loading Kedro project context. ... Error occurred when loading project and running context pipeline.
Read more >
kedro.framework.context — Kedro 0.17.6 documentation
KedroContext is the base class which holds the configuration and Kedro's main functionality. Error occurred when loading project and running context pipeline.
Read more >
kedro.framework.context — Kedro 0.17.2 documentation
kedro.framework.context provides functionality for loading Kedro project context. ... This is the default way to load the KedroContext object for normal ...
Read more >
Use Kedro with IPython and Jupyter Notebooks/Lab
The context variable allows you to interact with Kedro library components from within the Kedro Jupyter notebook. ../_images/jupyter_notebook_showing_context.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found