If the only reason to modify the path is for developers working from their working tree, then you should use an installation tool to set up your environment for you. virtualenv is very popular, and if you are using setuptools, you can simply run setup.py develop to semi-install the working tree in your current Python installation.

Answer from Ned Batchelder on Stack Overflow
🌐
Narkive
comp.lang.python.narkive.com › IRcwFeuc › pythonpath-vs-path
PYTHONPATH vs PATH?
PYTHONPATH=.;..;DIRECTORY-CONTAINING-scenarios.py Where DIRECTORY-CONTAINING-PYTHON-SCRIPTS.py is the directory containing the Python scripts . this actually is the PATH, not PYTHONPATH, and is correct if you installed the Python scripts to the Python scripts folder, and then start up from ...
🌐
Python.org
discuss.python.org › python help
Usage of PYTHONPATH - Python Help - Discussions on Python.org
August 9, 2022 - I am the beginner. I am still confused with the use of PYTHONPATH. The results of my research are as follows: I create the environement key ‘PYTHONPATH’ with the following values: C:\Program Files\Python\DLLs C:\Program Files\Python\Lib C:\Program Files\Python C:\Program Files\Python\Lib\site-packages C:\Users\…\AppData\Roaming\Python\Python310\site-packages I created a program to display the list of the function sys.path gives the following: [‘D:\Server\Python’, ‘C:\Program Files\P...
🌐
Reddit
reddit.com › r/learnpython › what does pythonpath=. do?
r/learnpython on Reddit: What does PYTHONPATH=. do?
January 20, 2017 -

I've often times run these commands blindly: export PYTHONPATH=. or PYTHONPATH=.. but I don't understand what they're doing...?

Top answer
1 of 2
2
It sets the path where Python looks for modules to the current directory or the directory one level above current. Why are you running those commands?
2 of 2
1
export creates or changes an environment variable for the current session in your operating system. ctrl-f for that particular one here to see what it means/does/is: https://docs.python.org/3/using/cmdline.html "." and ".." are coming from the relative path tradition. "." means "current directory" and ".." means parent directory (of the current directory). There is also "~" (for linux) which means "home directory" (which expands to "/home/your_user_name"). You can find more information about that here: https://en.wikipedia.org/wiki/Path_(computing)#Absolute_and_relative_paths You should not need to set these yourself, in almost all cases. I would look into how pip and virtualenv are used. The former installs libraries where python would expect to find them. I usually use it as python -m pip install some_library The latter creates a virtual environment (inside a folder) and puts basic libraries in it. virtualenv venv/ # create the venv directory in the current directory and copy over basic python stuff, for linux virtual venv\ # same as above if using Windows source venv/bin/activate # for linux, activate that virtual environment venv\Scripts\activate.bin # same as above if using Windows which python # in linux, check where your default python is; first executable listed should be the one inside venv/ or something is wrong where python # same as above, if using windows python -m pip install some_library # installs library inside that virtual environment/directory pip freeze > requirements.txt # records which libraries are installed; would in turn be used to install those libraries in another system/computer your_favorite_ide your_code.py # start editing your code using your virtual environment (if you're using Emacs, look into Elpy instead of this part; other IDEs also have their own way of configuring where the virtual environment is)
🌐
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
🌐
GeeksforGeeks
geeksforgeeks.org › pythonpath-environment-variable-in-python
PYTHONPATH Environment Variable in Python - GeeksforGeeks
September 5, 2020 - One of those variables is PYTHONPATH. It is used to set the path for the user-defined modules so that it can be directly imported into a Python program. It is also responsible for handling the default search path for Python Modules.
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › what-is-pythonpath-environment-variable-in-python
What is PYTHONPATH environment variable in Python?
August 26, 2023 - PYTHONPATH is an environment variable that extends Python's module search path.
🌐
Reddit
reddit.com › r/learnpython › sys.path and pythonpath
r/learnpython on Reddit: sys.path and pythonpath
December 15, 2016 -

As per the documents:

A list of strings that specifies the search path for modules. Initialized from the environment variable PYTHONPATH, plus an installation-dependent default.

As initialized upon program startup, the first item of this list, path[0], is the directory containing the script that was used to invoke the Python interpreter. If the script directory is not available (e.g. if the interpreter is invoked interactively or if the script is read from standard input), path[0] is the empty string, which directs Python to search modules in the current directory first. Notice that the script directory is inserted before the entries inserted as a result of PYTHONPATH.

A program is free to modify this list for its own purposes.

So sys.path is basically the path of the current directory and the paths resulting from the PYTHONPATH environmental variable.

If I open up the python repl, sys.path outputs:

['', '/usr/lib/python3.4', '/usr/lib/python3.4/plat-x86_64-linux-gnu', '/usr/lib/python3.4/lib-dynload', '/home/mike/.local/lib/python3.4/site-packages', '/usr/local/lib/python3.4/dist-packages', '/usr/lib/python3/dist-packages']

However, if I echo PYTHONPATH on the commandline:

echo $PYTHONPATH

Nothing outputs. If the PYTHONPATH environmental variable isn't set then how does python know which paths to use?

🌐
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
🌐
MacRumors
forums.macrumors.com › software › developers › apple programming
Help: PYTHONPATH vs. system PATH | MacRumors Forums
August 30, 2011 - So say the pyuic4 command is in ... your .bash_profile file and subsequent shells would also see it. The PYTHONPATH variable is used by python to find packages....
Top answer
1 of 4
84

You don't have to set either of them. PYTHONPATH can be set to point to additional directories with private libraries in them. PYTHONHOME sets the location of default libraries.

Documentation:

PYTHONHOME
Change the location of the standard Python libraries. By default, the libraries are searched in prefix/lib/pythonversion and exec_prefix/lib/pythonversion, where prefix and exec_prefix are installation-dependent directories, both defaulting to /usr/local.

When PYTHONHOME is set to a single directory, its value replaces both prefix and exec_prefix. To specify different values for these, set PYTHONHOME to prefix:exec_prefix.

PYTHONPATH
Augment the default search path for module files. The format is the same as the shell’s PATH: one or more directory pathnames separated by os.pathsep (e.g. colons on Unix or semicolons on Windows). Non-existent directories are silently ignored.

In addition to normal directories, individual PYTHONPATH entries may refer to zipfiles containing pure Python modules (in either source or compiled form). Extension modules cannot be imported from zipfiles.

The default search path is installation dependent, but generally begins with prefix/lib/pythonversion (see PYTHONHOME above). It is always appended to PYTHONPATH.

An additional directory will be inserted in the search path in front of PYTHONPATH as described above under Interface options. The search path can be manipulated from within a Python program as the variable sys.path.

2 of 4
31

For most installations, you should not set these variables since they are not needed for Python to run. Python knows where to find its standard library.

The only reason to set PYTHONPATH is to maintain directories of custom Python libraries that you do not want to install in the global default location (i.e., the site-packages directory).

Make sure to read: http://docs.python.org/using/cmdline.html#environment-variables

🌐
Upgrad
upgrad.com › home › blog › data science › python path: what it is and how to set it up correctly
Python Path: What It Is and How to Set It Up Correctly
July 24, 2026 - It tells your OS where to search for any executable program, including python.exe, git, node and others. When PATH includes your Python installation folder, typing python in any terminal window works instantly. PYTHONPATH is specific to Python.
🌐
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.
🌐
Post.Byes
post.bytes.com › home › forum › topic › python › pythonpath and python_path
PYTHONPATH and PYTHON_PATH - Post.Byes - Bytes
December 4, 2007 - Re: PYTHONPATH and PYTHON_PATH loial wrote: Is there any difference? > Does it matter which I use? Yes, it does matter. The former is interpreted by Python, the latter isn't. Christian · Post Cancel · Previous template Next · All times are GMT. This page was generated at 1 minute ago.
🌐
PyTutorial
pytutorial.com › python-path-management-pythonpath-and-syspath
PyTutorial | Python Path Management: PYTHONPATH and sys.path
May 10, 2025 - import sys sys.path.append('/path/to/your/modules') import your_module # Now Python can find it · PYTHONPATH is environment-wide. sys.path is process-specific. Use PYTHONPATH for system-wide changes.
🌐
Python
docs.python.org › 3 › library › sys_path_init.html
The initialization of the sys.path module search path — Python 3.15.1 documentation
The first entry in the module search path is the directory that contains the input script, if there is one. Otherwise, the first entry is the current directory, which is the case when executing the interactive shell, a -c command, or -m module. The PYTHONPATH environment variable is often used to add directories to the search path.
🌐
freeCodeCamp
forum.freecodecamp.org › curriculum help
What is PYTHONPATH? - Curriculum Help - The freeCodeCamp Forum
January 4, 2021 - The Path, as an Environment Variable, is a set of paths to different executable programs. Adding Python directory to your Path is what allows you to, for example, execute Python scripts directly from your terminal by typing python somescript.py ...
🌐
Stack Overflow
stackoverflow.com › questions › 39363544 › difference-between-adding-path-to-pythonpath-and-installing-your-own-module
python - Difference between adding path to PYTHONPATH and installing your own module - Stack Overflow
PYTHONPATH is a valid way of doing this, but in my (personal) opinion it's more useful if you have a whole different place where you keep your python variables.