What is PYTHONPATH
The PYTHONPATH is a variable in Python that the interpreter uses to locate modules by searching through the paths specified in sys.path.
sys.path is a list that includes, in order
- The directory of the script (if applicable).
- Paths specified in the environmental variable
PYTHONPATH. - Other paths depending on the Python installation on your system.
So, when you import a module, Python searches through these paths in order to find the module.
For example, on my system
| |
To view the value of PYTHONPATH
| |
In Linux, you can add a new path to PYTHONPATH like this
| |