Member-only story
How PYTHONPATH Cost My Friend a Job Offer
A small environment variable, a big interview disaster.
Non-Medium Members Can Read It Here
The import mechanism is a fundamental part of Python. Many new developers find it simple at first, but as projects grow, understanding imports becomes more challenging. With several moving parts like where Python looks for modules and packages, It’s easy to run into issues. By the end of this article, you’ll learn key details that many Python developers overlook.
Understanding PYTHONPATH
What is PYTHONPATH?
PYTHONPATH
is an environment variable that specifies additional directories for the Python interpreter to search for modules and packages. It acts as a supplement to Python’s default module search path, allowing you to include custom directories.
Let’s try to understand this with an example.
.
├── main.py
└── package
└── maths.py
main.py
from maths import add, sub
print(add(1, 2))
print(sub(1, 2))
package/maths.py
def add(a, b):
return a + b
def sub(a, b):
return a - b