[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
🌐
Python.org
discuss.python.org › python help
Usage of PYTHONPATH - Python Help - Discussions on Python.org
August 9, 2022 - 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 ...
🌐
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.
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
What is Pythonpath used for?
Pythonpath is an environment variable that is used to specify the location of Python libraries. It is typically used by developers to ensure that their code can find the required Python libraries when it is run.
🌐
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]
🌐
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.
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

🌐
Redreamality
redreamality.com › blog › pythonpathvs-code
How to Set PYTHONPATH on Windows, Linux, macOS and VS Code
August 21, 2025 - Use python3 instead of python if that is the command for your intended interpreter. PYTHONPATH is an environment variable that allows users to add extra directories to the list of paths that the Python interpreter searches for modules and packages.
🌐
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
Find elsewhere
🌐
AskPython
askpython.com › python › built-in-methods › pythonpath-in-shell
How to Get the Pythonpath in Shell? - AskPython
3 weeks ago - Python can read the environment inherited from its launching shell with os.getenv. The following command assigns an empty-string fallback to pythonpath but prints a separate lookup without that fallback, so an unset variable prints None.
🌐
Simons-rock
hope.simons-rock.edu › ~pshields › cs › python › pythonpath.html
PYTHONPATH
name: PYTHONPATH, type: string, value: /Users/username/desktop · Save this as environment.plist (the suffix is crucial), and then move it into the .MacOSX directory that you just created. You will need to log out and log back in before this takes effect -- but once it does take effect, Python will know about your desktop, whether you are working from the terminal, from Idle, or from the MacPython IDE.
🌐
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.
🌐
Python
docs.python.org › 3 › using › windows.html
4. Using Python on Windows — Python 3.15.2 documentation
If the environment variable PYTHONPATH exists, as described in Environment variables, its entries are added next. Note that on Windows, paths in this variable must be separated by semicolons, to distinguish them from the colon used in drive identifiers (such as C:\). Additional “application paths” can be added in the registry as subkeys of \SOFTWARE\Python\PythonCore{version}\PythonPath under both the HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE hives.
🌐
Python
docs.python.org › 3 › library › sys_path_init.html
The initialization of the sys.path module search path — Python 3.15.1 documentation
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.
🌐
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)
🌐
Real Python
realpython.com › add-python-to-path
How to Add Python to PATH – Real Python
July 23, 2026 - You may need to add Python to PATH if you’ve installed Python, but typing python on the command line doesn’t seem to work.
🌐
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 the Python interpreter where to look for additional modules and packages beyond the standard library. If you have custom Python modules stored outside your project folder, PYTHONPATH helps Python find them during import.
🌐
Medium
bryantson.medium.com › use-of-pythonpath-for-python-setup-fe36eb0a8cae
Use of “PYTHONPATH” for Python setup | by Bryant Jimin Son | Medium
January 26, 2026 - When Python starts, directories defined in PYTHONPATH are inserted into sys.path (usually near the beginning).
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-set-python-environment-variable-pythonpath-on-linux
How to set Python environment variable PYTHONPATH on Linux?
March 24, 2026 - Python search paths: /usr/lib/python3.x/site-packages /home/user/myproject ... Use export PYTHONPATH to add custom module paths on Linux. Add the export command to ~/.bashrc for permanent configuration.
🌐
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