sys.path: How Python finds the modules you import

sys.path: How Python finds the modules you import

You say “import mymod”. Where does Python look?

Check sys.path, a list of directory names (strings) where it searches.

By default:

– Current dir (empty string)
– Standard library
– site-packages

The first match wins, which can lead to unpleasant surprises — be careful!