I suggest not to rely on the raw PYTHONPATH because it can vary depending on the OS.

Instead of the PYTHONPATH value in the os.environ dict, use sys.path from the sys module. This is preferrrable, because it is platform independent:

import sys
print(sys.path)

The value of sys.path is initialized from the environment variable PYTHONPATH, plus an installation-dependent default (depending on your OS). For more info see

https://docs.python.org/2/library/sys.html#sys.path

https://docs.python.org/3/library/sys.html#sys.path

Answer from Maxime Lorant on Stack Overflow
Discussions

To print python's sys.path from the command line - Stack Overflow
I want to print python's sys.path from the command line, but this one is not working: python -m sys -c "print (sys.path)" although print -c "import sys; print (sys.path)" woul... More on stackoverflow.com
🌐 stackoverflow.com
debian - $PYTHONPATH and sys.path don't seems to match - Unix & Linux Stack Exchange
In the same time, when I print the content of sys.path, there is 10 different paths which aren't the same than those contained into $PATH (and obviously in $PYTHONPATH). More on unix.stackexchange.com
🌐 unix.stackexchange.com
Python 3.6 and Windows 8: Adding path (PYTHONPATH/SYS.PATH) to include own modules in project/file.
do you mean __init__.py? More on reddit.com
🌐 r/learnpython
6
3
August 25, 2017
[ELI5] What is sys.path?
It's not a file, it's basically a "variable" that determines where on the file system Python will look for modules to import. So, if you run import whatever, Python will first search the current directory, and then start looking through every directory in sys.path until it finds a module named whatever or runs out of places to look (and raises an ImportError). More on reddit.com
🌐 r/learnpython
2
3
September 25, 2016
People also ask

How do I add PYTHONPATH inside a Python script?
Changing os.environ["PYTHONPATH"] changes the process environment and can affect child processes started afterwards. For an import in the running interpreter, add the intended directory to sys.path before importing, or install the package into that interpreter’s environment.
🌐
askpython.com
askpython.com › python › built-in-methods › pythonpath-in-shell
How to Get the Pythonpath in Shell? - AskPython
Is PYTHONPATH required to import installed packages?
Python adds applicable package locations through its normal initialization. If an installed package cannot be imported, identify the active interpreter before adding extra paths.
🌐
askpython.com
askpython.com › python › built-in-methods › pythonpath-in-shell
How to Get the Pythonpath in Shell? - AskPython
How do I set multiple directories in PYTHONPATH?
Join directory paths with the operating system’s separator. It is a colon on Linux and macOS and a semicolon on Windows, and os.pathsep reports the appropriate character.
🌐
askpython.com
askpython.com › python › built-in-methods › pythonpath-in-shell
How to Get the Pythonpath in Shell? - AskPython
🌐
GeeksforGeeks
geeksforgeeks.org › python › sys-path-in-python
sys.path in Python - GeeksforGeeks
August 21, 2024 - THROUGH ENVIRONMENT VARIABLES- An environment variable that contains the path an interpreter can take while looking for modules can be employed. Once set, it hints interpreter with directories to locate a module. The following example shows how this can be done. PYTHONPATH=C:\Users\Vanshi\Desktop · Python · # importing module import sys # printing all directories sys.path ·
🌐
Note.nkmk.me
note.nkmk.me › home › python
Check and Add the Module Search Path in Python: sys.path | note.nkmk.me
May 12, 2023 - sys.path — System-specific parameters and functions — Python 3.11.3 documentation · sys.path is a list of strings specifying the module search path. You can view these paths using print().
🌐
Medium
medium.com › @gokulg.me › python-sys-module-from-beginner-to-advanced-b0f6bc73c8c2
Python sys Module: From Beginner to Advanced | by Gokul G | Medium
February 26, 2025 - Python searches for modules in directories listed in sys.path. You can append a new path dynamically: sys.path.append("/custom/path/to/module") print(sys.path)
Find elsewhere
🌐
Linux Hint
linuxhint.com › sys-path-append-python
How to Use Sys.path.append() in Python – Linux Hint
By declaring the following, we can check the current Python path: import sys from pprint import pprint pprint(sys.path) Here, the pprint module is just used to make things look pretty, so you can ignore that part, and concentrate on the rest. All we’re trying to do here is to print out sys.path.
🌐
YouTube
youtube.com › watch
Python Programming 53 - Sys.path and Changing Module Paths - YouTube
Start your software dev career - https://calcur.tech/dev-fundamentals 💯 FREE Courses (100+ hours) - https://calcur.tech/all-in-ones🐍 Python Course - https:...
Published: September 10, 2020
🌐
How to Use Linux
howtouselinux.com › home › understanding sys.path in python
understanding sys.path in Python - howtouselinux
October 9, 2025 - To access a function or variable in an imported module, you need to use the dot (.) operator. For example, if you want to use the print function from the sys module, you would use the following syntax: ... Despite these potential problems, sys.path is a powerful tool that can make your life as a Python programmer a lot easier.
🌐
W3docs
w3docs.com › home › code snippets › python › how do i find out my pythonpath using python?
How do I find out my PYTHONPATH using Python? | W3docs
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:
🌐
Dummies
dummies.com › article › technology › programming-web-design › python › how-to-find-path-information-in-python-148336
How to Find Path Information in Python | dummies
December 28, 2021 - You see the Python Shell window appear. Type import sys and press Enter. Type for p in sys.path: print(p) in a new cell and click Run Cell
Author:
🌐
GitHub
gist.github.com › bngsudheer › 8b84b2e4dd5440333621e603104ccf6c
Print $PYTHONPATH · GitHub
print-python-path.py · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters ·
🌐
PythonAnywhere
help.pythonanywhere.com › pages › DebuggingImportError
Debugging with sys.path / ImportError issues | PythonAnywhere Help
May 13, 2015 - If it loads OK, it will drop you into a Python shell. Try doing the import manually at the command line. Then, check whether they really are coming from where you think they are: from foo.bar import baz import foo print(foo.__file__) # this should show the path to the module. Is it what you expect? import sys print('\n'.join(sys.path)) # does this show the files and folders you need?
🌐
YouTube
youtube.com › watch
PYTHON sys.path and PYTHONPATH - YouTube
Where does Python look to find modules and packages? How can you adjust the Python search path so that modules that you create can be located.
Published: July 23, 2021
🌐
GitHub
github.com › pybind › pybind11 › discussions › 4511
Pybind11 and python sys.path · pybind/pybind11 · Discussion #4511
May 5, 2023 - #include <pybind11/stl.h> #include <pybind11/pybind11.h> #include <pybind11/embed.h> #include <pybind11/numpy.h> namespace py = pybind11; int main() { py::scoped_interpreter guard{}; py::exec("import sys\nprint(sys.path)"); } ... > ./main ['', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '/usr/lib/python3.10/site-packages'] ... In [1]: import sys In [2]: print(sys.path) ['/usr/bin', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '', '/home/xxx/.local/lib/python3.10/site-packages', '/usr/lib/python3.10/site-packages']
Author: pybind
🌐
Reddit
reddit.com › r/learnpython › python 3.6 and windows 8: adding path (pythonpath/sys.path) to include own modules in project/file.
r/learnpython on Reddit: Python 3.6 and Windows 8: Adding path (PYTHONPATH/SYS.PATH) to include own modules in project/file.
August 25, 2017 -

Hello! I'm already getting tired of including the same things in each file and re-writing code, so I created a folder for my own modules and put my own 'tools' in there. I added a PYTHONPATH variable to windows variable list (as well as put the path in the PATH variable), I have a (blank) 'init.py' in the directory of my module, but still when I type "import ..." it isn't showing up still. I've also appended it to sys.path via the sys.path.append('c:/users/..../myModules/') but still, nothing. ???? wtf? I've read about 20 pages on it, and tried everything, but nothing is working, so it's probably something really stupid.