[image] Pejamide: I am the beginner. I am still confused with the use of PYTHONPATH. Then do not mess with it. In the 7 years I am programming Python now, I never needed to change something on it. Python sets it to sensible values. Why do you want to change it? [image] Pejamide: I wonde… Answer from Mholscher on discuss.python.org
🌐
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
🌐
GeeksforGeeks
geeksforgeeks.org › python › pythonpath-environment-variable-in-python
PYTHONPATH Environment Variable in Python - GeeksforGeeks
January 9, 2026 - PYTHONPATH is an environment variable that tells Python where to look for modules and packages beyond the standard library and installed site-packages.
Discussions

Usage of PYTHONPATH
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\L... More on discuss.python.org
🌐 discuss.python.org
7
0
August 9, 2022
What is PYTHONPATH?
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 · You can see which directories are included ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
2
0
January 4, 2021
What does PYTHONPATH=. do?
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? More on reddit.com
🌐 r/learnpython
7
2
January 20, 2017
python - What exactly should be set in PYTHONPATH? - Stack Overflow
I'm going through and writing a setup doc for other developers at work for a python project and I've been reading up on the PYTHONPATH environment variable. I'm looking at my current development system and think I have a few things set wrong that is causing my IDE (IntelliJ) to behave incorrectly ... More on stackoverflow.com
🌐 stackoverflow.com
People also ask

How do I create a Pythonpath variable?
To create a Pythonpath variable, you will need to first open the Command Prompt.  Once the Command Prompt is open, you will need to type in the following command: setx /M Pythonpath "C:\Python27\Lib".  And you should know that creating a Pythonpath environment variable in Python will be changing depending on your operating system and whether you want the variable to be permanent. On Windows, you can use the set command to create a Pythonpath variable:set Pythonpath=C:\python On Mac or Linux, you can use the export command to create a Pythonpath variable:export Pythonpath =/usr/local/lib/python
🌐
simplilearn.com
simplilearn.com › home › resources › software development › understanding the python path environment variable in python
Understanding the Python Path Environment Variable in Python [Updated]
How do I add an environment variable in Pythonpath?
Following a few steps will allow you to add an environment variable: By setting the Pythonpath environment variable. By adding manually to the path in the file.  By using the os.environ module method.  Then you can also use the os.environ["key"] = "value" syntax to add a single environment variable.
🌐
simplilearn.com
simplilearn.com › home › resources › software development › understanding the python path environment variable in python
Understanding the Python Path Environment Variable in Python [Updated]
Is SYS path the same as Pythonpath?
The SYS path is a list of directories that Python interprets to search for when it starts up.  The Pythonpath is a list of directories that the Python interpreter will search for when it tries to resolve a module name.  So, both look the same but are quite different.
🌐
simplilearn.com
simplilearn.com › home › resources › software development › understanding the python path environment variable in python
Understanding the Python Path Environment Variable in Python [Updated]
🌐
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.
🌐
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...
🌐
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.
🌐
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 ...
Find elsewhere
🌐
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)
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

🌐
Simons-rock
hope.simons-rock.edu › ~pshields › cs › python › pythonpath.html
PYTHONPATH
If PYTHONPATH is already defined, just click edit and add the paths you want to the end of the list that is already there (separating paths by semicolons). In both cases the paths listed in PYTHONPATH will be appended to the locations that PYTHON already knows about, i.e., they do not overwrite these locations. But you should be careful anyway not to lose any of the paths that are already there since they may be used by Python extensions or applications. The above uses what are called shortened path names (= the first six characters of a directory name followed by ~1) in order to handle directories like Documents and Settings that have spaces in their name.
🌐
YouTube
youtube.com › watch
What Is PYTHONPATH? Resolve Module Import Errors in Python Easily - YouTube
Configure Python paths to seamlessly manage imports and enhance your efficiency as a QA Automation Engineer.▼▼▼ *YOUR NEXT STEP (FREE COURSE)* ▼▼▼🎓 *Get My ...
Published: April 22, 2024
🌐
YouTube
youtube.com › watch
PYTHONPATH Explained, How to Use PYTHONPATH | How to Python 1 | Python Tutorials - YouTube
In this video we’ll be go over how to set up your PYTHONPATH in a linux terminal and windows command prompt to be able to use GitHub repositories you’ve clon...
Published: October 7, 2021
Views: 8K
🌐
Python
docs.python.org › 3 › library › sys_path_init.html
The initialization of the sys.path module search path — Python 3.15.2 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.
🌐
C# Corner
c-sharpcorner.com › interview-question › what-is-pythonpath
What is PYTHONPATH?
PYTHONPATH is an environment variable which you can set to add additional directories where python will look for modules and packages .
🌐
Net Informations
net-informations.com › python › intro › path.htm
How to set python path
PYTHONPATH aids in the search for imported modules, essentially assisting in module lookup. Thus, when you import modules within your Python scripts, PYTHONPATH is additionally consulted to identify directories potentially containing the sought-after module.
🌐
Flevo CFD
flevo.cfd › posts › pythonpath
What is PYTHONPATH - Flevo CFD
December 4, 2023 - The PYTHONPATH is a variable in Python that the interpreter uses to locate modules by searching through the paths specified in sys.path. sys.path is a list that includes, in order The directory of the script (if applicable). Paths specified in the environmental variable PYTHONPATH.
🌐
Lino-framework
hosting.lino-framework.org › pythonpath
The Python Path — Hosting Guide
A collection of things to know when setting up the PYTHONPATH or diagnosing related problems. ... It is an environment variable used by Python itself. It defines the places from where to import Python modules.
🌐
YouTube
youtube.com › watch
How To Add Python to PATH in Windows - YouTube
The tutorial explains how to add Python to the Windows PATH in two different ways, allowing users to run Python scripts and access Python packages directly f...
Published: September 28, 2024