Python behind the scenes: how the Python import system works
The Python import system doesn’t just seem complicated – it is complicated. So even though the documentation is really good, it doesn’t give you the full picture of what’s going on. The only way to get such a picture is to study what happens behind the scenes when Python executes an import statement. And that’s what we’re going to do today.
source