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

Sys.path is included in the current directory by default
Hi, I am trying a custom build of python 3.11 on linux, I see that sys.path has current directory by default, I would like to change this behavior by changing the cpython source, >>> import sys >>> sys.path ['', '/usr/local/lib/python311.zip', '/home/mohammed/python/Python-3.11.0/Lib', ... More on discuss.python.org
🌐 discuss.python.org
6
0
March 29, 2023
Does changing default python path to anaconda python affect software centre
Hi, Recently i installed anaconda on my system and changed the default python to anaconda python export PATH="/usr/local/anaconda/bin:$PATH" default python path was - export PATH="/usr/bin/python/bin:$PATH" By doing this i can launch my environment directly from terminal. More on forum.manjaro.org
🌐 forum.manjaro.org
0
0
January 31, 2022
path - Changing default python to another version - Stack Overflow
Depending on what platform you are on, this is changed differently, but either way the point is to list the Python3 path before the Python2 path. ... I have edited the post. please check that again :) ... Since you have Linux, and if you want to simply type "python" instead of "python3" in ... More on stackoverflow.com
🌐 stackoverflow.com
How to get the "Downloads" folder path on Windows
Bare with me, typing this on my phone Use os.path.join( os.getenv('USERPROFILE'), 'Downloads') More on reddit.com
🌐 r/learnpython
8
20
April 5, 2016
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.
    >>> 
    
🌐
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.
🌐
Edureka
edureka.co › blog › add-python-to-path
Add Python To Path | How To Add A Python Path | Edureka
December 5, 2024 - One of the most important things to note when you are adding Path to Python in Unix or Linux is that, /usr/local/bin/python is the default path of the Python directory.
Find elsewhere
🌐
Tutorialspoint
tutorialspoint.com › python › python_environment.htm
Python - Environment Setup
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" and press Enter.
🌐
DaniWeb
daniweb.com › programming › software-development › threads › 485410 › python-path-linux
python path Linux [SOLVED] | DaniWeb
September 26, 2014 - The format is the same as the shell's ... The default search path is installation dependent, but generally begins with ${prefix}/lib/python<version> (see PYTHONHOME above)....
🌐
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.
🌐
Medium
medium.com › @furkangozukara › how-to-change-default-python-on-a-linux-machine-a200d9655543
How To Change Default Python On A Linux Machine - Furkan Gözükara - PhD Computer Engineer, SECourses - Medium
January 3, 2024 - How To Change Default Python On A Linux Machine Let's say you have installed Python into the following folder /home/ubuntu/Python-3.10.13 To set it default python version open a terminal Execute the …
🌐
Manjaro Linux
forum.manjaro.org › support › third-party software
Does changing default python path to anaconda python affect software centre - Third-Party Software - Manjaro Linux Forum
January 31, 2022 - Hi, Recently i installed anaconda on my system and changed the default python to anaconda python export PATH="/usr/local/anaconda/bin:$PATH" default python path was - export PATH="/usr/bin/python/bin:$PATH" By doing this i can launch my environment directly from terminal.
🌐
Uchicago
geosci.uchicago.edu › ~rtp1 › PrinciplesPlanetaryClimate › Python › ShellsNStuff.html
About Shells, Paths and Environment Variables
On a Linux system you do the same, except you don't need the -s flag. Be warned, though, that if you do this after you have installed Python, then the default python command may not point to the Python you installed, because the installer may not have set up a configuration file for the new shell you are using. [**ADD LINK to "Which python am I using," PATH variable and how to fix this if necessary.] Note that you only have to issue the chsh command once to change your default shell; you don't have to do it every time you log in.
🌐
Quora
quora.com › How-do-I-find-a-Python-path-in-Linux
How to find a Python path in Linux - Quora
Answer (1 of 5): This works with every executable - use the which command [code]$> which python3.9 [/code]If you are able to use the command ‘python3.9’ at the command line then the ‘which’ command above will tell you the path to that command. If you need to find the path from within ...
🌐
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
🌐
Linux Mint Forums
forums.linuxmint.com › board index › main edition support › beginner questions
no $PYTHONPATH environment variable? - Linux Mint Forums
September 4, 2013 - To add directories to your PATH you can add them to your .bashrc. for example you can add PATH=$PATH:/home/[username]/python/userlib.
🌐
Enterprise DNA
blog.enterprisedna.co › where-is-python-installed
Where is Python Installed? A Quick Guide – Master Data Skills + AI
Python is normally installed in the system’s default program files directory. On Windows, it’s typically found in the “C:\PythonXX” folder. On Linux or Mac, it’s often in “/usr/local/bin/pythonX.X”. You can check your Python installation path by running “python –version” ...