Q44: How does Python's Import System search for modules via sys.path?

When an import statement executes, Python searches locations listed in sys.path in order:

  1. Directory containing the input script.
  2. Directories listed in PYTHONPATH.
  3. Standard library directories.
  4. Installed third-party site-packages.
Key Takeaways
  • Search path sequence stored in sys.path list.
  • Loaded modules are cached in sys.modules dictionary to prevent re-parsing.
Knowledge Check

Where does Python cache successfully imported module objects to prevent redundant disk reads?