Albert Thomas

Research engineer in machine learning at Huawei


My go-to reference on Python imports

Published September 29, 2025

A while ago I was working on a project where I ran into issues with Python imports and I found the following blog post: The Definitive Guide to Python import Statements. I think it is a great resource that really deserves more publicity. I still come back to it once in a while when I have an import error as it helps me understand what is going on instead of just trying random fixes. I also share it with colleagues when they mention similar problems. I wanted to mention it here partly so it is easier for me to find again and partly because I think others might benefit from it too.

What I always find useful to remember from it:

  • where and in which order Python looks for the module you want to import
  • how sys.path is initialized: it contains the location of the Python script and not the current working directory
  • you cannot import from the parent directory of your Python script when you are running it directly