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.

Answer from Mark Tolonen on Stack Overflow
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

🌐
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 ...
Discussions

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 - How to add to the PYTHONPATH in Windows, so it finds my modules/packages? - Stack Overflow
I have a directory which hosts all of my Django apps (C:\My_Projects). I want to add this directory to my PYTHONPATH so I can call the apps directly. I tried adding C:\My_Projects\; to my Windows ... More on stackoverflow.com
🌐 stackoverflow.com
python - PYTHONPATH on Linux - Stack Overflow
I'm novice in this, and I have started learning Python, but I have some questions that I'm not be able to understand, What exactly is the PYTHONPATH (on Ubuntu)? Is it a folder? Is Python provided by More on stackoverflow.com
🌐 stackoverflow.com
PYTHONPATH with Venv
If you are using virtualenvwrapper you can set environment variables in a postactivate script, as mentioned here https://stackoverflow.com/questions/9554087/setting-an-environment-variable-in-virtualenv Elsewhere you mention you want to do this to help with your project imports. If these are projects with a setup.py, just install them in your virtualenv (or if you want to use them where they are - use python setup.py develop ) If they don't have a setup.py, I recommend adding one. More on reddit.com
🌐 r/Python
6
0
March 4, 2018
🌐
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.
🌐
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.
Find elsewhere
🌐
Python
docs.python.org › 3 › using › cmdline.html
1. Command line and environment — Python 3.15.1 documentation
In addition to normal directories, individual PYTHONPATH entries may refer to zipfiles containing pure Python modules (in either source or compiled form).
🌐
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
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
🌐
Redreamality
redreamality.com › blog › pythonpathvs-code
How to Set PYTHONPATH on Windows, Linux, macOS and VS Code
August 21, 2025 - PYTHONPATH adds directories to Python’s module search path, sys.path.
🌐
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
🌐
LinuxQuestions.org
linuxquestions.org › questions › linux-newbie-8 › what-on-earth-is-$pythonpath-4175574196
[SOLVED] What on earth is $PYTHONPATH
March 7, 2016 - Sorry for all these questions guys... But I've been trying to make sense of this statement for several days. Add the module directory to your PYTHONPA
🌐
AskPython
askpython.com › python › built-in-methods › pythonpath-in-shell
How to Get the Pythonpath in Shell? - AskPython
3 weeks ago - Importing a module makes Python look through a list of folders to find it. PYTHONPATH is an environment variable, a setting your shell passes to programs, that adds extra folders to that list when Python starts.
🌐
GitHub
github.com › microsoft › vscode-docs › issues › 4232
Kindly provide a working example of using PYTHONPATH variable in env file · Issue #4232 · microsoft/vscode-docs
January 14, 2021 - In the existing documentation on using PYTHONPATH, it is not shown as to how to add the PYTHONPATH to the env file and not clear if VS code will override any global environment variables that are d...
🌐
Medium
medium.com › @jameskabbes › importing-your-local-package-with-pythonpath-c459dc209c7
Importing your Local Package with PYTHONPATH | by James Kabbes | Medium
September 21, 2023 - PYTHONPATH is an environment variable that Python uses to locate modules and packages on your system.
Top answer
1 of 3
73
  1. PYTHONPATH is an environment variable which you can set to add additional directories where python will look for modules and packages. e.g.:

    # make python look in the foo subdirectory of your home directory for   
    # modules and packages 
    export PYTHONPATH=${PYTHONPATH}:${HOME}/foo 
    

    Here I use the sh syntax. For other shells (e.g. csh,tcsh), the syntax would be slightly different. To make it permanent, set the variable in your shell's init file (usually ~/.bashrc).

  2. Ubuntu comes with python already installed. There may be reasons for installing other (independent) python versions, but I've found that to be rarely necessary.

  3. The folder where your modules live is dependent on PYTHONPATH and where the directories were set up when python was installed. For the most part, the installed stuff you shouldn't care about where it lives -- Python knows where it is and it can find the modules. Sort of like issuing the command ls -- where does ls live? /usr/bin? /bin? 99% of the time, you don't need to care -- Just use ls and be happy that it lives somewhere on your PATH so the shell can find it.

  4. I'm not sure I understand the question. 3rd party modules usually come with install instructions. If you follow the instructions, python should be able to find the module and you shouldn't have to care about where it got installed.

  5. Configure PYTHONPATH to include the directory where your module resides and python will be able to find your module.

2 of 3
46
  1. PYTHONPATH is an environment variable
  2. Yes (see https://unix.stackexchange.com/questions/24802/on-which-unix-distributions-is-python-installed-as-part-of-the-default-install)
  3. /usr/lib/python2.7 on Ubuntu
  4. you shouldn't install packages manually. Instead, use pip. When a package isn't in pip, it usually has a setuptools setup script which will install the package into the proper location (see point 3).
  5. if you use pip or setuptools, then you don't need to set PYTHONPATH explicitly

If you look at the instructions for pyopengl, you'll see that they are consistent with points 4 and 5.