W3docs

How do I find out my PYTHONPATH using Python?

You can use the sys module in Python to access the sys.path variable, which contains a list of directories that Python looks in for modules to import.

You can use the sys module in Python to access the sys.path variable, which contains a list of directories that Python looks in for modules to import. Here is a code snippet that you can use to print out the current value of sys.path:

use sys library's path method

import sys
print(sys.path)

<div class="alert alert-info flex not-prose"> Watch a course <span class="hidden md:block">Watch a video course </span> Python - The Practical Guide</div>

The directories listed in sys.path are searched in order, so if multiple versions of a module are found, the version in the first directory in the list will be imported. The first item in the list is the current working directory, followed by directories listed in the PYTHONPATH environment variable, if it is set.