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.

Answer from mgilson on Stack Overflow
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.

Discussions

ubuntu - How to set up Python path? - Unix & Linux Stack Exchange
PYTHONPATH=/usr/lib/my_python_distribution export PYTHON ... root1@master:/usr/lib/python2.7$ echo $PATH /home/root1/anaconda3/bin:/home/root1/NAI/Execution/HDE/x86_64.linux/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/root1/java/jdk1.8... More on unix.stackexchange.com
🌐 unix.stackexchange.com
December 31, 2015
python - Permanently add a directory to PYTHONPATH? - Stack Overflow
On linux you can create a symbolic link from your package to a directory of the PYTHONPATH without having to deal with the environment variables. Something like: ... For me it worked when I changed the .bash_profile file. Just changing .bashrc file worked only till I restarted the shell. ... export ... More on stackoverflow.com
🌐 stackoverflow.com
linux - Adding to $PYTHONPATH with bash script - Stack Overflow
I wrote a bash script to add to my $PYTHONPATH. My .sh file has the following: sudo echo export PYTHONPATH=$PYTHONPATH:/path/to/new/python/module >> ~/.bashrc What I want to be added to my .... More on stackoverflow.com
🌐 stackoverflow.com
python - $PYTHONPATH is not working at all - Unix & Linux Stack Exchange
I am using Linux Mint 19.2, kernel Linux 4.15.0-54-generic and Python 2.7.15+. Edit: Unfortunately the other topic does not help me, because, even though i am using $PYTHONPATH, i cannot import the packages lying in the defined path. I want to permanently add this path and normally it works like this, but $PYTHONPATH doesn't seem to work at all. Edit 2: This is the command line, when I try to use $PYTHONPATH: $ export ... More on unix.stackexchange.com
🌐 unix.stackexchange.com
People also ask

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
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]
🌐
AskPython
askpython.com › python › built-in-methods › pythonpath-in-shell
How to Get the Pythonpath in Shell? - AskPython
1 month ago - You do not need to copy Python’s standard-library or site-packages directories into PYTHONPATH. In Bash on Linux or macOS, print the variable with printf, keeping its value together through quoting and accepting an unset variable through parameter expansion.
🌐
Redreamality
redreamality.com › blog › pythonpathvs-code
How to Set PYTHONPATH on Windows, Linux, macOS and VS Code
August 21, 2025 - On Unix-like systems (such as macOS and Linux), setting environment variables is similar and typically involves modifying the shell configuration files. The path separator is a colon (:). This setting is only valid for the current terminal session. ... To make PYTHONPATH available every time you open a new terminal, you need to add it to your shell configuration file.
🌐
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
🌐
GitHub
bic-berkeley.github.io › psych-214-fall-2016 › using_pythonpath.html
Using PYTHONPATH — Functional MRI methods
$ # Set PYTHONPATH to path to the working directory + /code $ # This is for the "bash" shell on Unix / git bash on Windows $ export PYTHONPATH="$PWD/code" $ # Now the script can find "a_module" $ python3 scripts/a_script.py Running useful function
Top answer
1 of 4
5

I'm assuming that when you installed anaconda 2, you manually set the PYTHONPATH environment variable, by putting something like

PYTHONPATH=/home/user/anaconda2/python
export PYTHONPATH

in your .bash_profile or .bash_rc.

But since you deleted the /home/user/anacanda2/ directory, that path no longer exists.

Thus you want to change PYTHONPATH to point to the executable in /usr/lib, by changing the above to

PYTHONPATH=/usr/lib/my_python_distribution
export PYTHON
2 of 4
3
  1. execute the command: echo $PATH

    root1@master:/usr/lib/python2.7$ echo $PATH
    /home/root1/anaconda3/bin:/home/root1/NAI/Execution/HDE/x86_64.linux/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/root1/java/jdk1.8.0_74/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/home/root1/NAI/hadoop-2.7.3/bin
    
  2. Remove your anaconda3 from your path variable that is

    /home/root1/anaconda3/bin:
    
  3. Again set PATH variable with remaining information like below

    export PATH=/home/root1/NAI/Execution/HDE/x86_64.linux/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/root1/java/jdk1.8.0_74/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/home/root1/NAI/hadoop-2.7.3/bin
    
  4. Execute python command and should redirect to your python interpreter

    root1@master:/usr/lib/python2.7$ python
    Python 2.7.14 (default, Sep 18 2017, 00:00:00) 
    [GCC 4.8.4] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    
🌐
Real Python
realpython.com › add-python-to-path
How to Add Python to PATH – Real Python
July 23, 2026 - This command adds export PATH="<PATH_TO_PYTHON>:$PATH" to the end of .profile. The command export PATH="<PATH_TO_PYTHON>:$PATH" prepends <PATH_TO_PYTHON> to the PATH environment variable.
🌐
IT trip
en.ittrip.xyz › python
Setting and Using the PYTHONPATH Environment Variable: A Guide for Project Utilization | IT trip
December 3, 2024 - After activating the virtual environment, run the following to set PYTHONPATH: Linux/Mac: export PYTHONPATH=/path/to/your/directory:$PYTHONPATH
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-set-your-python-path-on-linux
How to set your python path on Linux?
March 24, 2026 - # Add to ~/.bashrc or ~/.zshrc echo 'export PYTHONPATH=${PYTHONPATH}:${HOME}/mymodules' >> ~/.bashrc source ~/.bashrc
🌐
LinuxVox
linuxvox.com › blog › python-path-linux
Mastering Python Paths on Linux — linuxvox.com
You can do this temporarily for the current shell session or permanently by adding it to your shell profile. export PYTHONPATH=/path/to/your/modules:$PYTHONPATH python your_script.py
🌐
Urban Fresh Produce
urbanfreshproduce.ca › post › export-pythonpath
export pythonpath
December 17, 2024 - Always remember to replace /path/to/your/modules with the actual path to your modules or packages. On Linux and macOS systems, you typically use the export command in your shell (Bash, Zsh, etc.):
🌐
DaniWeb
daniweb.com › programming › software-development › threads › 485410 › python-path-linux
python path Linux [SOLVED] | DaniWeb
The easiest, safest way to make your private library directory available without replacing Python’s defaults is to append that directory to PYTHONPATH in a shell startup file so it persists. Put the export line into the appropriate file for your session (interactive shells use ~/.bashrc, login/GUI sessions often read ~/.profile or ~/.bash_profile) and restart or source that file.
🌐
Edureka
edureka.co › blog › add-python-to-path
Add Python To Path | How To Add A Python Path | Edureka
December 5, 2024 - If you are using the standard flavour of Linux, open up the bash shell and type the following phrase, export PATH=”$PATH:/usr/local/bin/python” and press Enter.
Top answer
1 of 1
2

I'm running Mint 19.3 and kernel version 4.15.0-106-generic - so not far off from you.

(python3-venv) me@mycomp:chap10-Batteries_Included$ cat/etc/*release
DISTRIB_ID=LinuxMint
DISTRIB_RELEASE=19.3
DISTRIB_CODENAME=tricia
DISTRIB_DESCRIPTION="Linux Mint 19.3 Tricia"
...
(python3-venv) me@mycomp:chap10-Batteries_Included$ uname -r
4.15.0-106-generic

running in a Python 3 virtual environment. I'm working on "Beginning Python, From Novice to Professional" by Magnus Lie Hetland and got to Chapter 10 where it talks about this very thing. When I first get into my shell, I find nothing assigned to $PYTHONPATH either:

(python3-venv) me@mycomp:chap10-Batteries_Included$ echo $PYTHONPATH
 
(python3-venv) me@mycomp:chap10-Batteries_Included$

So I do what is suggested everywhere on the web, and in the book($PWD being my working directory, which happened to be the directory I wanted added):

(python3-venv) me@mycomp:chap10-Batteries_Included$ export PYTHONPATH=$PYTHONPATH:$PWD
(python3-venv) me@mycomp:chap10-Batteries_Included$ echo $PYTHONPATH
:/home/me/Documents/CodingProjects/python/Beginning-Python/book/chap10-Batteries_Included
(python3-venv) me@mycomp:chap10-Batteries_Included$

And there we go, it's there:

(python3-venv) me@mycomp:chap10-Batteries_Included$ python -O
Python 3.6.9 (default, Apr 18 2020, 01:56:04) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys, pprint
>>> pprint.pprint(sys.path)
['',
 '/home/me/Documents/CodingProjects/python/Beginning-Python/book/chap10-Batteries_Included',
 '/usr/lib/python36.zip',
 '/usr/lib/python3.6',
 '/usr/lib/python3.6/lib-dynload',
 '/home/me/python3-venv/lib/python3.6/site-packages']
>>> 

I noticed, and would have commented had I been able to without having 50 points on here, that you have export export PYTHONPATH=$PYTHONPATH:.... - you only need export once. You can add this export PYTHONPATH=... to your ~/.profile to make it permanent, too. I hope this helps.

🌐
Amazonaws
bebi103.caltech.edu.s3-website-us-east-1.amazonaws.com › 2014 › handouts › ho2_setting_pythonpath.html
Setting your PYTHONPATH environment variable
If you are using Linux, you should launch Canopy from the command line. To set your PYTHONPATH, either edit your ~/.profile file or the appropriate rc file for the shell you are using. Here ~/ is an abbreviation for your home directory. In my case, I would add the following line to my ~/.profile ...
🌐
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