Python needs to know where to find the files you want to use. The module search path tells Python where to look for these files.
Module search path in Python
import sys print(sys.path)
sys.path is a list of folder paths where Python looks for modules.
You can add new paths to sys.path to tell Python to look in other places.
import sys print(sys.path)
import sys sys.path.append('/my/custom/path') print(sys.path)
import os import sys sys.path.insert(0, os.path.abspath('libs')) print(sys.path)
This program shows all the folders where Python looks for modules. It helps you understand where Python searches when you use import.
import sys print('Current module search paths:') for path in sys.path: print(path)
The exact paths in sys.path depend on your Python installation and environment.
You can modify sys.path at runtime, but it only affects the current program run.
For permanent changes, you can set the PYTHONPATH environment variable before running Python.
Python uses a list of folders called the module search path to find modules when you import them.
You can see and change this list using sys.path.
Understanding the module search path helps fix import errors and organize your code better.