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.

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

python - Permanently add a directory to PYTHONPATH? - Stack Overflow
You could add the path via your pythonrc file, which defaults to ~/.pythonrc on linux. ie. ... You could also set the PYTHONPATH environment variable, in a global rc file, such ~/.profile on mac or linux, or via Control Panel -> System -> Advanced tab -> Environment Variables on windows. More on stackoverflow.com
🌐 stackoverflow.com
Add Python to path in Ubuntu
I wouldn't have thought you need to add python to the path explicitly, unless this version of python is different to your system's version of python (in which case having two versions of python in the path is probably a bad idea -- you don't want applications which invoke python getting an unexpected python version). Depending on your needs, you might want to look into something like pyenv . E: clarified something. More on reddit.com
🌐 r/learnpython
5
2
October 10, 2020
Adding python scripts to $PATH variable without having to use “Python3 script.py”
There are three parts to the answer, (1) The file should be an executable, so you need to set the file permissions, ie., chmod +x script.py (2) The file should be present in one of the directories specified in the PATH variable, so you need to add the following in .bashrc or .bash_profile, (reopen the terminal after adding this) export PATH="${PATH}:/home/scripts" (3) Specify the interpreter to use for your script. Add the following as the first line in script.py, #!/usr/bin/python3 Thats it. After doing the above, you can simply run, script.py ... More on reddit.com
🌐 r/linux4noobs
11
7
July 29, 2020
The absolute maze that is installing python and path variables
The official python (python.org) on Windows? The modern standard install on Windows does not use PATH at all anymore. Anyone telling you to use that is trying to make the modern install backwards compatible with the old-school way of doing things. Instead, python comes with the " python launcher ", which is the command "py". To run a file: py myfile.py To install a module: py -m pip install Etc. py is automatically associated with .py and .pyw files, so you can just doubleclick them to run as well. BUT WAIT, THERE'S A CATCH! The normal, proper way to develop python code is to make an isolated virtual environment for each project. If you do this it will activeate the old-school python and pip commands. So if you are working in a virtual environment To run a file: python myfile.py To install a module: pip install Note most good IDEs have the virtual environment management built in and often enabled by default. More on reddit.com
🌐 r/learnpython
99
208
January 28, 2022
🌐
Real Python
realpython.com › add-python-to-path
How to Add Python to PATH – Real Python
January 30, 2023 - In this tutorial, you'll learn about how to add Python, or any other program, to your PATH environment variable. You'll be covering the procedure in Windows, macOS, and Linux and find out what PATH is and why it's important.
🌐
Tutorialspoint
tutorialspoint.com › python › python_environment.htm
Python - Environment Setup
To add the Python directory to the path for a particular session in Unix − · In the csh shell − type setenv PATH "$PATH:/usr/local/bin/python" and press Enter. In the bash shell (Linux) − type export PATH="$PATH:/usr/local/bin/python" ...
🌐
GitHub
bic-berkeley.github.io › psych-214-fall-2016 › using_pythonpath.html
Using PYTHONPATH — Functional MRI methods
From the advanced system settings dialog, choose the “Environment variables” button: In the Environment variables dialog, click the “New” button in the top half of the dialog, to make a new user variable: Give the variable name as PYTHONPATH and the value is the path to the code directory.
🌐
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 command sets the PYTHONPATH environment variable to /home/user/myproject and also includes the previous value of PYTHONPATH in case it was already set. Note that the path should be separated by a colon (:) on Linux.
Find elsewhere
🌐
scipher
scipher.wordpress.com › 2010 › 05 › 10 › setting-your-pythonpath-environment-variable-linuxunixosx
Setting Your PYTHONPATH environment variable (Linux/Unix/OsX) | scipher
May 10, 2010 - If you do not have a PYTHONPATH set up yet you can simply copy the one above (lines 4 AND 5) into your file and replace the useless paths that I include for paths to where your python packages live. ... # Linux /usr/lib/python2.x/site-packages/ # Mac /Library/Frameworks/Python.framework/Versions/2.x/lib/python2.x/site-packages/
🌐
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 it to any value of your choice. PYTHONHOME: This is an alternative to module search path that can be used in Python.
🌐
Uchicago
geosci.uchicago.edu › ~rtp1 › PrinciplesPlanetaryClimate › Python › ShellsNStuff.html
About Shells, Paths and Environment Variables
However, the Finder does not examine the PYTHONPATH variable, so it won't find modules installed in nonstandard places. There is a workaround for this, but to keep things simple, I recommend starting up idle by typing the command into a terminal window. For canopy , which uses ipython as its interpreter, the specification of paths can be handled by editing the ipython startup file, as explained in Courseware . This task is also automatically handled by my setpath.py utility.
🌐
Eyesopen
docs.eyesopen.com › toolkits › python › quickstart-python › linuxosx_pythonpath.html
PYTHONPATH Installation — Toolkits -- Python
The PYTHONPATH environment variable can be set in your shell startup script ~/.bashrc For example, if the package was untarred into the /usr/local directory: PYTHONPATH=/usr/local/OpenEye-toolkits-python3-linux-x64-|pypkgversion| export PYTHONPATH · The syntax and location may vary if you ...
🌐
PhoenixNAP
phoenixnap.com › home › kb › sysadmin › how to add python to path on windows, linux, and mac
How to Add Python to PATH on Windows, Linux, and Mac
December 12, 2025 - In this article, you will learn how to add the Python binary to PATH on Windows, Linux, and macOS.
🌐
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
🌐
The Tech Deck
thetechdeck.hashnode.dev › how-to-add-python-to-your-path-on-linux
How to Add Python to Your PATH on Linux - OmniGuru
December 11, 2023 - To add Python to your PATH permanently on Linux, you'll need to edit shell startup scripts. Which one depends on your Linux shell: ... At the bottom of the file, add the following line, replacing the path with your Python install directory:
🌐
Linux Mint Forums
forums.linuxmint.com › board index › main edition support › beginner questions
Python PATH - Linux Mint Forums
Even more important if it's a python script, given it's quite a bit lower down than shell. If you're placing it somewhere like /usr/bin/ like I do with some of my main shell programs, (those which should also be owned by root and be in the root group, to prevent tampering) intend it to be used globally, and have been careful with how you've written it, then yeah, by all means, provided you stick with a usual permission set like 755.
🌐
Great Learning
mygreatlearning.com › blog › it/software development › how to add python to path?
How To Add Python To Path?
November 15, 2024 - In the "Environment Variables" window (Windows) or terminal (macOS/Linux), find the "Path" variable under the "System variables" section. Windows: Select the "Path" variable and click "Edit."