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
- import statement — A statement that makes code from another module or package available by name in the current file.
- module — A file of code whose functions, classes and variables other files can use by importing it.
- site-packages — The folder where pip installs third-party packages for a particular Python or virtual environment.
- shadowing — Using a name that already means something, such as list or str, for your own variable, which hides the original in that part of the program.
Taught in
- Where Python Lives: PATH And Versions — Hands-on Python: Complete Video Course & Book
- Modules And The Import System — Hands-on Python: Complete Video Course & Book
- pip, requirements, and installing packages — Hands-on Python: Complete Video Course & Book
- When awk Runs Out: Python Data Types, Modules And Virtual Environments For Admins — CompTIA Linux+ (XK0-006) Exam Prep