Python - Module path and import

Introduction

You can list a path of names separated by periods:

import dir1.dir2.mod 

The same goes for from statements:

from dir1.dir2.mod import x 

The "dotted" path dir1.dir2.mod is mapping to a path through the directory hierarchy on your computer.

The ending would be mod.py or similar extension.

The preceding statements indicate that on your machine there is a directory dir1, which has a subdirectory dir2, which contains a module file mod.py or similar.

These imports imply that dir1 resides within Python module search path.

dir0\dir1\dir2\mod.py               # Or mod.pyc, mod.so, etc. 

The container directory dir0 needs to be added to your module search path.

The leftmost component in a package import path is relative to a directory included in the sys.path.

Related Topic