kedro: Investigate `KedroSession.create: ModuleNotFoundError: No module named 'None'`
Description
Following the documentation on creating and running a session causes an error: https://kedro.readthedocs.io/en/0.18.1/kedro.framework.session.session.KedroSession.html
When creating a KedroSession, the validate_settings() appears not to get the right ‘PACKAGE_NAME’, and thus fails.
However, following the following page does work: https://kedro.readthedocs.io/en/stable/kedro_project_setup/session.html
Context
Starting a Kedro session from within Python.
Steps to Reproduce
from kedro.framework.session import KedroSession
with KedroSession.create('<package_name>') as session: session.run()
Expected Result
Running the kedro project similarly to ‘kedro run’
Actual Result
>>> from kedro.framework.session import KedroSession
>>> session = KedroSession.create('my_package_name')
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\my_user\Environments\my_env\lib\site-packages\kedro\framework\session\session.py", line 138, in create
validate_settings()
File "C:\Users\my_user\Environments\my_env\lib\site-packages\kedro\framework\project\__init__.py", line 223, in validate_settings
importlib.import_module(f"{PACKAGE_NAME}.settings")
File "C:\Users\my_user\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'None'
Your Environment
Include as many relevant details about the environment in which you experienced the bug:
- Kedro version used (
pip show kedroorkedro -V): 0.18.0 and 0.18.1 - Python version used (
python -V): 3.7.9 - Operating system and version: Microsoft Windows 10 Enterprise, Version 10.0.19042 Build 19042
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 18 (12 by maintainers)
@noklam Nice investigating!
Great question about the difference between
bootstrap_projectandconfigure_project. This isn’t at all obvious and something I always forget…bootstrap_projectis used when running in “project mode”. i.e. you are in your project root directory and runningkedro ...commands.pyproject.tomlis in the same directory, and hencemetadatais available.configure_projectis used when running in “packaged mode”. i.e. you have donekedro packageand are running your project as a Python package. The crucial difference is thatpyproject.tomlis not present in the Python package as it just gives build-time information used during packaging, and hence there is nometadataavailable.This should become a bit clearer when I finally get around to continuing work on https://github.com/kedro-org/kedro/pull/1423.
@PetervanHeck Thanks. From my testing with
0.17.7and0.18.1, it will both throw errors. But I don’t fully understand why they give different errors yet. It would be great if you can give me an example that run successfully, a fake project is fine.(Noted my working directory is called
mshere.)0.17.7
0.18.1
I’ll update the issue description a little bit.