# Absolute vs Relative Imports in Python

DevFeed: [Absolute vs Relative Imports in Python](<https://devfeed.tech/articles/absolute-vs-relative-imports-in-python-122118.md>)

Original publisher: [Read original article](<https://realpython.com/absolute-vs-relative-python-imports/>)

Author: Mbithe Nzomo

Published: 2026-11-07T14:00:00Z

Content type: tutorial

Language: en

Sources: [Real Python](<https://devfeed.tech/sources/real-python.md>)

Topics: [import](<https://devfeed.tech/topics/import.md>), [Python](<https://devfeed.tech/topics/python.md>)

Tags: [absolute](<https://devfeed.tech/tags/absolute.md>), [best-practices](<https://devfeed.tech/tags/best-practices.md>), [compare](<https://devfeed.tech/tags/compare.md>), [cons](<https://devfeed.tech/tags/cons.md>), [python](<https://devfeed.tech/tags/python.md>)

## AI overview

Python first checks `sys.modules`, then built-in modules, then directories in `sys.path` when resolving an import; an unresolved name raises `ModuleNotFoundError`. PEP 8 guidance in the text is to place imports after module comments and docstrings, group standard library, third-party, and local imports with blank lines, and order each group alphabetically. Absolute imports give a full path from the project root, are clearer, remain valid when the importing statement moves, and are preferred by PEP 8, but can become verbose. Explicit relative imports use dots to refer to the current or parent package and can shorten long paths, but are harder to read and can be affected by directory changes. They require Python to know the module's package: run a module with `python -m package.module`; running its file directly can raise `ImportError: attempted relative import with no known parent package`. The text recommends absolute imports unless the path is complex enough to make them too long.

## Source excerpt

Compare Python relative imports with absolute imports, weigh the pros and cons of each, and learn best practices for writing clean import statements.