If you're using bash (on a Mac or GNU/Linux distro), add this to your ~/.bashrc

export PYTHONPATH="${PYTHONPATH}:/my/other/path"
Answer from awesomo on Stack Overflow
๐ŸŒ
GitHub
bic-berkeley.github.io โ€บ psych-214-fall-2016 โ€บ using_pythonpath.html
Using PYTHONPATH โ€” Functional MRI methods
Luckily, we can make the PYTHONPATH value be set for any terminal session, by setting the environment variable default.
Discussions

ubuntu - How to set up Python path? - Unix & Linux Stack Exchange
I have uninstall anaconda2. but now when I run Python command in terminal it says "bash: /home/user/anaconda2/python: No such file or directory" now how can I set to Python when I have python 2.7 i... More on unix.stackexchange.com
๐ŸŒ unix.stackexchange.com
December 31, 2015
python - Is there a way to set PYTHONPATH permanently? - Stack Overflow
Every day, when I open an Ubuntu terminal and want to run a python project, I have to run previously export PYTHONPATH=$(pwd). Is there a way to avoid doing this every time I switch on my computer?... More on stackoverflow.com
๐ŸŒ stackoverflow.com
TLJH permanent global PYTHONPATH environment variable
We have implemented TLJH no problem. The object is to share .ipynb files but most required importing python code that is in a โ€œ/home/py/ director. What I have learned is that if I can start a program using the terminal, python will use the PYTHONPATH variable. More on discourse.jupyter.org
๐ŸŒ discourse.jupyter.org
2
0
August 14, 2020
linux - How do I add a Python import path permanently? - Stack Overflow
I know that I can add an import path to Python like this: import sys sys.path.append("/path/to/directory/") But, when I restart Python, this is gone. I'd find it quite annoying if I had to do thi... More on stackoverflow.com
๐ŸŒ stackoverflow.com
May 10, 2012
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.

๐ŸŒ
Ask Ubuntu
askubuntu.com โ€บ questions โ€บ 381425 โ€บ how-to-change-environmental-variable-permanently
bash - How to change environmental variable permanently? - Ask Ubuntu
echo $PYTHONPATH in a terminal or import os; print os.environ['PYTHONPATH'] (from Python, will work if such a variable was defined) To set an environment variable for all applications, read this.
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.
    >>> 
    
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-set-python-environment-variable-pythonpath-on-linux
How to set Python environment variable PYTHONPATH on Linux?
May 2, 2023 - ... This sets the PYTHONPATH ... only affects the current shell session. If you want to set it permanently, you will need to add the export command to a startup script such as .bashrc or .bash_profile....
Find elsewhere
๐ŸŒ
LinuxQuestions.org
linuxquestions.org โ€บ questions โ€บ linux-newbie-8 โ€บ permanent-python-path-4175574997
Permanent Python Path
Linux Mint - Cinnamon python 2.7.6 and Python 3.4.3 bash I know this is basic...but...I am trying to get my python path set up so that I can import
๐ŸŒ
Net Informations
net-informations.com โ€บ python โ€บ intro โ€บ path.htm
How to set python path
csh shell: type setenv PATH "$PATH:/usr/local/bin/python" and press Enter. bash shell (Linux): type export ATH="$PATH:/usr/local/bin/python" and press Enter. sh or ksh shell: type PATH="$PATH:/usr/local/bin/python" and press Enter. /usr/local/bin/python is the default path of the Python directory.
๐ŸŒ
Jupyter Community Forum
discourse.jupyter.org โ€บ jupyterhub
TLJH permanent global PYTHONPATH environment variable - JupyterHub - Jupyter Community Forum
August 14, 2020 - We have implemented TLJH no problem. The object is to share .ipynb files but most required importing python code that is in a โ€œ/home/py/ director. What I have learned is that if I can start a program using the terminal, python will use the PYTHONPATH variable.
๐ŸŒ
Uchicago
geosci.uchicago.edu โ€บ ~rtp1 โ€บ PrinciplesPlanetaryClimate โ€บ Python โ€บ ShellsNStuff.html
About Shells, Paths and Environment Variables
The other commonly used shell is csh (pronounced "c-shell" -- get the joke?). In this shell, and its relative tcsh, to set PYTHONPATH you would type ... You can tell if your shell is csh or some flavor of it because the command line prompt ends with a % sign. The configuration file for csh is ... which will also be used by tcsh if the file .tcsh isn't found . If you prefer to run csh, on Mac OSX you can change your default shell by typing: ... On a Linux system you do the same, except you don't need the -s flag.
๐ŸŒ
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
๐ŸŒ
iheavy
iheavy.com โ€บ home โ€บ how to set pythonpath
How to Set PYTHONPATH - iheavy - Devops + Cloud Solutions Architect
February 10, 2026 - To set PYTHONPATH permanently, you need to modify your systemโ€™s environment variables.
๐ŸŒ
Edureka
edureka.co โ€บ blog โ€บ add-python-to-path
Add Python To Path | How To Add A Python Path | Edureka
December 5, 2024 - In Unix or Linux, this is named as pythonrc.py and using this command loads the utilities that modify PYTHONPATH. PYTHONCASEOK: This is an Environmental Variable that is specific to Windows. When you use this variable, Python will find the first case insensitive match in an import statement. In order to activate this variable, you can set ...