What is PYTHONPATH?

PYTHONPATH is an environment variable that tells Python about extra folders to search when you import a module. Python normally looks in the current folder and the standard library first, and then in the folders listed in PYTHONPATH.

Set it on macOS or Linux like this:

export PYTHONPATH=/home/robin/mylibs

On Windows (Command Prompt):

set PYTHONPATH=C:\mylibs

You can check the full list of search folders from Python itself.

import sys
print(sys.path)

Output (your computer will show different folders):

Tutorials Class - Output Window

[”, ‘/home/robin/mylibs’, ‘/usr/lib/python3.12’, …]

Your own folder appears in the list. This is useful when you keep shared code outside the project, but a virtual environment and proper packages are usually a cleaner way.


Learn more about the similar topics:
Tutorials
Python Introduction
Python Syntax
Python Comments
Python input() Function
Exercises & Assignments
No Content Found.
Interview Questions & Answers
What is Python?
Is Python an interpreted language?
What is an interpreted language?
What is PEP 8?
What are the key features of Python?
Is Python case-sensitive?
What is the use of the input() function in Python?