Cannot find a module imported by another module
Question:
I have a file structure like this
└── myproject
├── src
├── a.py
├── b.py
module a contains a
class that is imported in by module b
like this:
from src.a import some_class
when I try to import b
from another class:
from myproject.src import b
I get this error:
from src.a import some_class
ModuleNotFoundError: No module named 'src'
why can’t python find package src? how can I solve this?
Answers:
You can try this import in b.py
from .a import some_class
I have a file structure like this
└── myproject
├── src
├── a.py
├── b.py
module a contains a
class that is imported in by module b
like this:
from src.a import some_class
when I try to import b
from another class:
from myproject.src import b
I get this error:
from src.a import some_class
ModuleNotFoundError: No module named 'src'
why can’t python find package src? how can I solve this?
You can try this import in b.py
from .a import some_class