Member-only story
Use of “PYTHONPATH” for Python setup
PYTHONPATH
PYTHONPATH is an environment variable that affects Python’s module and package search path. It allows you to configure additional directories that the Python interpreter will search when processing import statements.
In other words, it is one of the key mechanisms for controlling where Python looks when importing modules.
Python Module and Package Search Path
1. Default Search Path
When the Python interpreter starts, it internally initializes a list called sys.path.
Typically, sys.path includes the following paths:
- The current working directory (or the directory containing the script)
- Standard library paths (e.g.,
/usr/lib/python3.9,C:\Python39\Lib) site-packages(where third-party packages are installed)- Paths specified in the
PYTHONPATHenvironment variable (if any)
2. Relationship Between PYTHONPATH and sys.path
When Python starts, directories defined in PYTHONPATH are inserted into sys.path (usually near the beginning).
This allows Python to search those directories before the standard library, increasing their priority, or to include project-specific library directories in the import path.







