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.

Better error message when missing __init__.py

See original GitHub issue

If a dotted path fails to import, we should check if the reason is a missing __init__.py file and suggest adding it. Current error:

Traceback (most recent call last):
  File "/Users/Edu/miniconda3/envs/ml-testing/lib/python3.9/site-packages/ploomber/cli/io.py", line 20, in wrapper
    fn(**kwargs)
  File "/Users/Edu/miniconda3/envs/ml-testing/lib/python3.9/site-packages/ploomber/cli/task.py", line 34, in main
    dag, args = _custom_command(parser)
  File "/Users/Edu/miniconda3/envs/ml-testing/lib/python3.9/site-packages/ploomber/cli/parsers.py", line 405, in _custom_command
    dag, args = load_dag_from_entry_point_and_parser(entry_point, parser,
  File "/Users/Edu/miniconda3/envs/ml-testing/lib/python3.9/site-packages/ploomber/cli/parsers.py", line 451, in load_dag_from_entry_point_and_parser
    dag, args = _process_file_dir_or_glob(parser)
  File "/Users/Edu/miniconda3/envs/ml-testing/lib/python3.9/site-packages/ploomber/cli/parsers.py", line 392, in _process_file_dir_or_glob
    dag = DAGSpec(dagspec_arg).to_dag()
  File "/Users/Edu/miniconda3/envs/ml-testing/lib/python3.9/site-packages/ploomber/spec/dagspec.py", line 424, in to_dag
    dag = self._to_dag()
  File "/Users/Edu/miniconda3/envs/ml-testing/lib/python3.9/site-packages/ploomber/spec/dagspec.py", line 473, in _to_dag
    process_tasks(dag, self, root_path=self._parent_path)
  File "/Users/Edu/miniconda3/envs/ml-testing/lib/python3.9/site-packages/ploomber/spec/dagspec.py", line 745, in process_tasks
    task, up = task_dict.to_task(dag)
  File "/Users/Edu/miniconda3/envs/ml-testing/lib/python3.9/site-packages/ploomber/spec/taskspec.py", line 298, in to_task
    return _init_task(data=data,
  File "/Users/Edu/miniconda3/envs/ml-testing/lib/python3.9/site-packages/ploomber/spec/taskspec.py", line 381, in _init_task
    task.on_finish = dotted_path.DottedPath(on_finish,
  File "/Users/Edu/miniconda3/envs/ml-testing/lib/python3.9/site-packages/ploomber/util/dotted_path.py", line 47, in __init__
    self._load_callable()
  File "/Users/Edu/miniconda3/envs/ml-testing/lib/python3.9/site-packages/ploomber/util/dotted_path.py", line 54, in _load_callable
    self._callable = load_callable_dotted_path(self._spec.dotted_path)
  File "/Users/Edu/miniconda3/envs/ml-testing/lib/python3.9/site-packages/ploomber/util/dotted_path.py", line 169, in load_callable_dotted_path
    loaded_object = load_dotted_path(dotted_path=dotted_path,
  File "/Users/Edu/miniconda3/envs/ml-testing/lib/python3.9/site-packages/ploomber/util/dotted_path.py", line 128, in load_dotted_path
    module = importlib.import_module(mod)
  File "/Users/Edu/miniconda3/envs/ml-testing/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: An error happened when trying to import dotted path "tests.quality.clean": No module named 'tests.quality'

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
edublancascommented, Oct 22, 2021

Sure! Feel free to reach out to us on Slack if you have questions.

A few tips to get started:

Essentially, once we detect the ImportError, we want to see if the module is importable, but there’s an __init__.py missing.

0reactions
edublancascommented, Oct 27, 2021

Hi @abhishak3. following up your discovery. you’re right. this isn’t an issue with the __init__.py file, it’s a module shadowing problem (see #405), let me know if you want to work on that one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Warn about missing __init__.py · Issue #2773 · python/mypy
If a package doesn't have an __init__.py file, the error message ... Better error messages for invalid Python package directory names #2775.
Read more >
python - Import error for package, am i missing an __init__.py
If you want a folder to be recognized as a package, that would be src in your case, it needs to contain. __...
Read more >
When Things Go Wrong — PyInstaller 5.7.0 documentation
PyInstaller sometimes terminates by raising a Python exception. In most cases the reason is clear from the exception message, for example “Your system...
Read more >
Working with the AWS CDK in Python
Python is a fully-supported client language for the AWS CDK and is considered ... There are also runtime type checkers that can improve...
Read more >
Troubleshoot Python errors in Azure Functions - Microsoft Learn
This error occurs when a Python function app is forced to terminate by the operating system with a SIGSEGV signal. This signal indicates ......
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