'Python finding subdirectories with pkgutil's extend_path

This is my folder structure

src
├── __init__.py
└── foo
    ├── __init__.py
    └── bar
        ├── __init__.py
        ├── events
        │   ├── __init__.py
        │   ├── execute
        │   │   ├── __init__.py
        │   │   ├── helloworld.py
        │   │   ├── run.py
        └── settings.py

$ cat src/foo/__init__.py outputs...

from pkgutil import extend_path

__path__ = extend_path(__path__, __name__)

in src/foo/bar/events/execute/run.py, I want to do something like this

from foo.bar.events.execute.helloworld import HelloWorld

I get the error

No module named 'foo.bar'

This is how I'm running my app

I understand it's not proper, but there's a reason I just simplified the question for brevity

$ python src/foo/bar/events/execute/run

How do I achieve importing this way from src/foo/bar/events/execute/run.py?

from foo.bar.events.execute.helloworld import HelloWorld


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source