Search code examples
pythonimportpylintstreamlit

Pylint gives error warning to working relative imports


I have the following file structure:

├── README.md
├── apps
│   ├── fire_analysis.py
│   └── rois.py
└── streamlit_app.py

File contents

  • streamlit_app.py
from apps import fire_analysis

  • apps/fire_analysis.py
from .apps import rois
print(rois.the_object)

  • apps/rois.py
the_object = 42 # the object that I want

The code works just fine. But I am getting the E0402: Attempted relative import beyond top-level package (relative-beyond-top-level) error warning from pylint.

How to resolve this warning? Am I doing the importing the wrong way in the fire_analysis.py?


Solution

  • It works for me to change the import of apps/fire_analysis.py to

    from . import rois
    

    telling python to search locally.