module search path

The list of folders Python searches, in order, when a program imports a module.

In more detail

It starts with the folder of the script being run, then the standard library, then site-packages. Because your own folder comes first, a file named random.py or math.py next to your program hides the real module, a classic and confusing bug. Print sys.path to see the list.

Example

import sys
print(sys.path)

Related terms

Taught in

References

Certification courses