How To Print Sys Path Python

If you want to see the system path for Python installed on your computer, you can print it in the Python shell. In this tutorial, we will show you how to print the sys path in Python.

Steps:

1. First, open a Python shell on your computer.

2. Then, import the sys module by typing the following command:

3. Once you have imported the sys module, you can print the sys path by typing the following command:

4. The output will show you the system path for Python installed on your computer.

Example output:

['', '/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/site-packages/MarkupSafe-1.0-py2.7-macosx-10.13-x86_64.egg', '/usr/local/lib/python2.7/site-packages/Pygments-2.2.0-py2.7.egg', '/usr/local/lib/python2.7/site-packages/entrypoints-0.2.3-py2.7.egg', '/usr/local/lib/python2.7/site-packages/jinja2-2.10-py2.7.egg', '/usr/local/lib/python2.7/site-packages/setuptools-28.8.0-py2.7.egg', '/usr/local/lib/python2.7/site-packages/IPython/extensions', '/Users/yourusername/.ipython']

Conclusion:

Printing the sys path in Python is a quick and easy way to view the system path for Python installed on your computer. This can be useful if you need to add a new module to your Python installation or if you’re troubleshooting an issue with your Python environment.

Full code: