Why This Happens
Relative imports like from . import module only work inside packages. If you run a file directly with python script.py, Python does not consider it part of a package, so relative imports fail.
The Problem
# mypackage/utils.py
from . import helpers
# Running: python mypackage/utils.pyThe Fix
# Option 1: Use absolute import
from mypackage import helpers
# Option 2: Run as module
# python -m mypackage.utilsStep-by-Step Fix
- 1
Run as a module
Use python -m package.module from the project root.
- 2
Use absolute imports
Replace from . import x with from package import x.
- 3
Add __init__.py
Ensure all directories have __init__.py files.
Bugsly catches this automatically
Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.
Try Bugsly free