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
Answer from gardenhead on Stack Exchange
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
January 30, 2023 - To see the value of any environment variable in Linux or macOS, you can use the echo command: ... $ echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/home/realpython/badpython:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games ยท Note that the $ symbol is used to tell the command line that the following identifier is a variable.
Discussions

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
Python - add PYTHONPATH during command line module run - Stack Overflow
If you are running the command from a POSIX-compliant shell, like bash, you can set the environment variable like this: PYTHONPATH="/path/to" python somescript.py somecommand ยท If it's all on one line, the PYTHONPATH environment value applies only to that one command. More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to add python to path and how to use it in commandline/powershell?
Reinstall Python from https://python.org . During the first step in setup, there'll be an option to add Python to PATH. Select it More on reddit.com
๐ŸŒ r/learnpython
13
1
October 25, 2025
Python and the PATH variable in Windows 10
If you type python and the store opens, Turn off the python alias in the Alias List in settings ( https://www.tenforums.com/tutorials/102096-manage-app-execution-aliases-windows-10-a.html ) More on reddit.com
๐ŸŒ r/Python
16
33
August 20, 2021
๐ŸŒ
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. In the sh or ksh shell โˆ’ type PATH="$PATH:/usr/local/bin/python" ...
๐ŸŒ
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 ยท You probably donโ€™t want to have to set PYTHONPATH every time you start up a terminal and run a Python script.
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.

๐ŸŒ
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 - Add Python to the PATH variable to execute it without specifying the path. This tutorial shows you how to do it on Windows, Linux, and macOS.
๐ŸŒ
Net Informations
net-informations.com โ€บ python โ€บ intro โ€บ path.htm
How to set python path
To add Python to the PATH environment ... to the Python installation directory. Locate the "Scripts" folder within the Python directory, copy its path, and then append it to the PATH variable using the system's environment variables settings....
Find elsewhere
๐ŸŒ
Uchicago
geosci.uchicago.edu โ€บ ~rtp1 โ€บ PrinciplesPlanetaryClimate โ€บ Python โ€บ ShellsNStuff.html
About Shells, Paths and Environment Variables
Then, you want to set PYTHONPATH to this directory. (To list multiple directories to be searched, just separate them by a colon, e.g. dir1:dir2:dir3 ). A slight complication is that Unix-like operating systems (including Linux and Mac OSX) offer various different flavors of the command-line processor, called "shells," and the way you set environment variables depends on which shell you are using.
๐ŸŒ
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 ...
๐ŸŒ
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.
๐ŸŒ
CodeGenes
codegenes.net โ€บ blog โ€บ how-to-add-python-to-path
How to Add Python to Path: A Comprehensive Guide โ€” codegenes.net
@echo off set PYTHON_PATH=C:\Users\John\AppData\Local\Programs\Python\Python39 setx /M PATH "%PATH%;%PYTHON_PATH%;%PYTHON_PATH%\Scripts" echo Python has been added to the PATH. ... On most Linux distributions, Python is installed in /usr/bin ...
๐ŸŒ
Great Learning
mygreatlearning.com โ€บ blog โ€บ it/software development โ€บ how to add python to path?
How To Add Python To Path?
November 15, 2024 - This blog will walk you through adding Python to PATH on Windows, macOS, and Linux. With step-by-step instructions and screenshots on how to add python path to environment variables, we'll make it effortless for you to integrate Python into your development workflow. By the end, you'll be ready to start using Python from the command line without having to navigate to its installation directory every time.
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ how to get the pythonpath in shell?
How to Get the Pythonpath in Shell? - AskPython
May 30, 2023 - After that, write the following line of code in it. export PYTHONPATH="/Users/kundansingh/opt/anaconda3/lib/python39.zip" Now set the source as the .bashrc , and your pythonpath is set.
๐ŸŒ
Linux Mint Forums
forums.linuxmint.com โ€บ board index โ€บ main edition support โ€บ beginner questions
no $PYTHONPATH environment variable? - Linux Mint Forums
September 4, 2013 - # the default umask is set in /etc/profile; for setting the umask # for ssh logins, install and configure the libpam-umask package. #umask 022 And I was told to use "#! /usr/bin/env python" rather than "#! usr/bin/python". Why is the latter better? ... Oops, sorry about that, add the line "PYTHONPATH=/usr/bin/python" to the file .bashrc and if the file isn't there just create it.
๐ŸŒ
DaniWeb
daniweb.com โ€บ programming โ€บ software-development โ€บ threads โ€บ 485410 โ€บ python-path-linux
python path Linux [SOLVED] | DaniWeb
September 26, 2014 - The search path can be manipulated from within a Python program as the variable sys.path. ... 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.
๐ŸŒ
Cloudinary
cloudinary.com โ€บ home โ€บ how to add python to path โ€“ and why it matters
How to Add Python to PATH โ€“ and Why It Matters
August 1, 2025 - C:\Users\YourName\AppData\Local\Programs\Python\Python311 ... Update environment variables. Open Start โ†’ Search for Environment Variables. Click Edit the system environment variables. Click Environment Variables.
๐ŸŒ
Redreamality's Blog
redreamality.com โ€บ blog โ€บ pythonpathvs-code
Setting PYTHONPATH Environment Variable: A Comprehensive Guide for All Platforms & VS Code Development
August 21, 2025 - Important Note: You need to reopen any existing Command Prompt or PowerShell windows for the new environment variable settings to take effect. 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.