You would probably also want this:

import sys
print(sys.path)

Or as a one liner from the terminal:

python -c "import sys; print('\n'.join(sys.path))"

Caveat: If you have multiple versions of Python installed you should use a corresponding command python2 or python3.

Answer from Vanuan on Stack Overflow
🌐
GitHub
gist.github.com › bngsudheer › 8b84b2e4dd5440333621e603104ccf6c
Print $PYTHONPATH · GitHub
Print $PYTHONPATH · Raw · 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 ·
🌐
GitHub
bic-berkeley.github.io › psych-214-fall-2016 › using_pythonpath.html
Using PYTHONPATH — Functional MRI methods
The PYTHONPATH variable has a value that is a string with a list of directories that Python should add to the sys.path directory list.
Discussions

python - how to print contents of PYTHONPATH - Stack Overflow
How can we print contents of PYTHONPATH variable. ... Obviously that means you don't have python path set in your machine. More on stackoverflow.com
🌐 stackoverflow.com
August 12, 2016
Current Directory not in PYTHONPATH
Issue description PYTHONPATH does not contain the current directory when using pipenv run Expected result When running something using run, for example tests pipenv run pytest tests/ The PYTHONPATH / sys.path should contain the current d... More on github.com
🌐 github.com
2
January 20, 2019
pathit - Just show me my PATH in way I can read it
honest question why didnt you just wrap printf "$PATH" | tr ":" "\n" | sort in a function and put it into your bashrc or equivalent? More on reddit.com
🌐 r/Python
23
8
January 28, 2024
python - How to get the PYTHONPATH in shell? - Stack Overflow
This gives me syntax error (pointing to end of import word - EOL while scanning string literal): python -c 'import os; print(os.environ["PYTHONPATH"])'. If I use double quote then it says "name 'PYTHONPATH' is not defined" 2019-10-17T12:26:23.173Z+00:00 More on stackoverflow.com
🌐 stackoverflow.com
March 22, 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
🌐
AskPython
askpython.com › python › built-in-methods › pythonpath-in-shell
How to Get the Pythonpath in Shell? - AskPython
3 weeks ago - I got None with PYTHONPATH unset, while an explicitly empty value produced an empty string. To read the value without the redundant assignment, use the shorter command below. Testing membership in os.environ distinguishes an absent variable from one that exists with an empty value. python3 -c "import os; print(os.getenv('PYTHONPATH'))" python3 -c "import os; print('PYTHONPATH' in os.environ)"
🌐
Delft Stack
delftstack.com › home › howto › python › print pythonpath in python
How to Print Contents of PYTHONPATH in Python | Delft Stack
February 2, 2024 - In the realm of Python development, the os module plays a pivotal role in accessing environment variables, among which the PYTHONPATH variable holds particular significance. This section focuses on leveraging the capabilities of the os module to retrieve and inspect the contents of the PYTHONPATH environment variable. ... import os def print_pythonpath(): pythonpath = os.getenv("PYTHONPATH") if pythonpath: print("PYTHONPATH:") paths = pythonpath.split(os.pathsep) for path in paths: print(f"- {path}") else: print("PYTHONPATH is not set.") if __name__ == "__main__": print_pythonpath()
Find elsewhere
🌐
GitHub
github.com › topics › pythonpath
pythonpath · GitHub Topics · GitHub
A simple python package to solve all your problems with pythonpath, work dir, file paths, module imports and environment variables.
🌐
GitHub
gist.github.com › gimbo › 6d8506ad66e13d14620d88e501376967
LR python path · GitHub
March 31, 2022 - $ cd .. $ python3 -c "import bar" Traceback (most recent call last): File "<string>", line 1, in <module> ImportError: No module named 'bar' $ export PYTHONPATH=/path/to/foo $ python3 -c "import bar" $ python3 -c "import sys; print('/path/to/foo' in sys.path)" True
🌐
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: ... 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.
🌐
GitHub
github.com › pypa › pipenv › issues › 3465
Current Directory not in PYTHONPATH · Issue #3465 · pypa/pipenv
January 20, 2019 - The PYTHONPATH / sys.path should contain the current directory so that packages containing modules to be tested can be found. I get errors like · E ModuleNotFoundError: No module named 'hello' And doing · pipenv run python import sys print(sys.path) Shows that the directory the command was executed from is not in the path.
Author: pypa
🌐
GeeksforGeeks
geeksforgeeks.org › pythonpath-environment-variable-in-python
PYTHONPATH Environment Variable in Python - GeeksforGeeks
September 5, 2020 - The PYTHONPATH variable holds a string with the name of various directories that need to be added to the sys.path directory list by Python. The primary use of this variable is to allow users to import modules that are not made installable yet. Let's try to understand the concept using an example. ... # user-defined module # saved as my_module.py def module_func(): print("You just imported the user-defined module")
🌐
GitHub
gist.github.com › mjhea0 › 6217875
python_path.sh · GitHub
GitHub Gist: instantly share code, notes, and snippets.
🌐
Reddit
reddit.com › r/python › pathit - just show me my path in way i can read it
r/Python on Reddit: pathit - Just show me my PATH in way I can read it
January 28, 2024 -

Got tired of scrolling through my PATH variable and decomposing it with something like echo $PATH | tr ":" "\n", so I wrote micro package to show the path by line, sort it alphabetically and extract lines of interest.

Question Answer
What's on my PATH? pathit show or pathit raw
Sort alphabetically pathit show --sort
Paths with mingw? pathit show --includes mingw
New content PATH without invalid dirs pathit show --purge --string

Maybe a better tool exists, but hope it is a useful utility - or at least a demo. Packaging done with `poetry` and few tests added. Code, bash equivalents and install instructions: https://github.com/epogrebnyak/what-the-path

Update: thanks to feedback from this thread, the options in pathit become the following. Note --string in specific - it allows to form a string that you can later use in your shell start file.

--sort     --no-sort    Sort output alphabetically. 
--includes TEXT
--excludes TEXT
--purge    --no-purge   Exclude invalid directories.  
--expand   --no-expand  Expand environment variables if found inside PATH.
--string   --no-string  Print a single string suitable for PATH content.
--display-numbers       Indicate directory order in PATH.
--color                 Use color to highlight errors.

Update 2: package renamed justpath and available through pip install justpath now. Also can display your PATH as JSON now.

🌐
Leemendelowitz
leemendelowitz.github.io › blog › how-does-python-find-packages.html
How does python find packages? // Lee On Coding // My blog about coding and stuff.
By comparing the sys.path from both the Ubuntu Python, which resides at /usr/bin/python, and the newly installed Python, which resides at /usr/local/bin/python, I could sort things out: >>> import sys >>> print '\n'.join(sys.path) /usr/lib/python2.7 /usr/lib/python2.7/plat-x86_64-linux-gnu /usr/lib/python2.7/lib-tk /usr/lib/python2.7/lib-old /usr/lib/python2.7/lib-dynload /usr/local/lib/python2.7/dist-packages /usr/lib/python2.7/dist-packages
🌐
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:
🌐
Codemia
codemia.io › home › knowledge hub › how do i find out my pythonpath using python?
How do I find out my PYTHONPATH using Python? | Codemia
September 23, 2025 - If the result is None, the variable is not set for the current Python process. That is normal on many systems. Python does not require PYTHONPATH to exist.
🌐
Simplilearn
simplilearn.com › home › resources › software development › understanding the python path environment variable in python
Understanding the Python Path Environment Variable in Python [Updated]
September 14, 2025 - Python path is an environment variable used to maintain directories of custom Python libraries. Learn how to set a python path variable on Windows and Mac now!
Address: 5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States