Python (Scripting) - List Python system paths using sys.path

by
Jeremy Canfield |
Updated: January 21 2025
| Python (Scripting) articles
Python modules are typically located somewhere below sys.path.
Here is how you would determine the system paths.
#!/usr/bin/python3
import sys
print("System Paths:")
for directory in sys.path:
print(f" {directory}")
Which should return something like this.
System Paths:
/home/john.doe
/usr/lib64/python27.zip
/usr/lib64/python2.7
/usr/lib64/python2.7/plat-linux2
/usr/lib64/python2.7/lib-tk
/usr/lib64/python2.7/lib-old
/usr/lib64/python2.7/lib-dynload
/usr/lib64/python2.7/site-packages
/usr/lib/python2.7/site-packages
However, let's say you have created your own module that contains functions and you want other Python scripts to be able to use the functions. If the Python module you created does not reside in one of the system paths, the following can be included in the other Python scripts to append the directory that contains the "master" Python script to the system paths.
sys.path.append("/tmp")
Did you find this article helpful?
If so, consider buying me a coffee over at