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
Discussions

How do I "set Python to PATH" without reinstalling Python?
Wesley Trayer is having issues with: I am currently at Timezones in the learn python track, and I wanted to install pytz on my computer. I read that all you needed to type was "pip ... More on teamtreehouse.com
๐ŸŒ teamtreehouse.com
1
October 1, 2017
ubuntu - How to set up Python path? - Unix & Linux Stack Exchange
When you installed anaconda2, did you add any PYTHONPATH directives to your startup file(s) (such as your ~/.bashrc)? You probably just need to remove these, rather than set any additional path. More on unix.stackexchange.com
๐ŸŒ unix.stackexchange.com
December 31, 2015
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
what does it mean to " Add python<version> to PATH " ?
The PATH environment variable holds a list of folders to search through when you attempt to run a program from the terminal. You want to tick that box during installation More on reddit.com
๐ŸŒ r/CodingHelp
3
3
December 29, 2021
๐ŸŒ
Real Python
realpython.com โ€บ add-python-to-path
How to Add Python to PATH โ€“ Real Python
July 23, 2026 - In this tutorial, youโ€™ve learned how to add Python, or any other program, to your PATH environment variable on Windows, Linux, and macOS. You also learned a bit more about what PATH is and why its internal order is vital to consider.
๐ŸŒ
Mimo
mimo.org โ€บ tutorials โ€บ python โ€บ how-to-add-python-to-path
How to Add Python to PATH
If pyenv which python fails, your shell init is missing. Add pyenv init lines for your shell (zsh or bash) and restart the terminal. What to look for: once pyenv is active, python usually points to a path under your home directory, not /usr/bin. On Linux, python3 is often the default command.
๐ŸŒ
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
Find elsewhere
๐ŸŒ
YouTube
youtube.com โ€บ chart explorers
ADD PYTHON TO PATH | When and how to add python to path - YouTube
A brief depiction of how to add python to path. Also, an explanation of when you might not want to add python to path. Python is a general purpose programmin...
Published: June 24, 2020
Views: 8K
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.
    >>> 
    
๐ŸŒ
Pygame
pygame.org โ€บ wiki โ€บ GettingStarted
GettingStarted - pygame wiki
This tricks the pygame config scripts, ... installed in /usr and other SDL libs installed in /usr/local. The command for this situation is "LOCALBASE=/usr/local python setup.py install"....
๐ŸŒ
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 - Click New and paste each path. Apply and restart terminal. Open a new command prompt and type python --version. If everything worked, youโ€™ll see the installed Python version. ... On most Unix-based systems, Python is already installed, but it may be under python3. To check, try the terminal command which python3. To make python run Python 3, add an alias in your shell config:
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ how-to-set-python-environment-variable-pythonpath-on-linux
How to set Python environment variable PYTHONPATH on Linux?
March 24, 2026 - Use export PYTHONPATH to add custom module paths on Linux. Add the export command to ~/.bashrc for permanent configuration.
๐ŸŒ
Linux Mint Forums
forums.linuxmint.com โ€บ board index โ€บ main edition support โ€บ beginner questions
Python PATH - Linux Mint Forums
You supposedly started the /home/ozramsay/code/hello.py script with a line like #!/usr/bin/python telling the system which interpreter to run the script through. If indeed and if you additionally tell the system that the script is in fact executable through ... chmod +x ~/code/hello.py you can invoke it simply as hello.py due to ~/code being in your PATH.
๐ŸŒ
Codidact
linux.codidact.com โ€บ posts โ€บ 287333
Adding Python 3.11 to `$PATH` - Linux Systems
First, as already brought up in a comment thread, it appears that the export command you added in your .bashrc is missing a final ". This should cause an error message to be printed when starting a shell, making it an easy error to spot. Second and more likely to be the problem, $PATH points to directories to search for executable files; it does not point directly at specific executable files. So if you have a python binary originally in the directory ~/cpython-3.11, then within that directory do a mv python python3.11, then want to be able to start it by giving only its name (not a full path) you will need to add the directory it is in (~/cpython-3.11) to your $PATH.
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ pathlib.html
pathlib โ€” Object-oriented filesystem paths
Added in version 3.13. Pure path objects provide path-handling operations which donโ€™t actually access a filesystem. There are three ways to access these classes, which we also call flavours:
๐ŸŒ
Astral
docs.astral.sh โ€บ uv โ€บ guides โ€บ install-python
Installing and managing Python | uv
3 weeks ago - Once Python is installed, it will be used by uv commands automatically. uv also adds the installed version to your PATH:
๐ŸŒ
FastAPI
fastapi.tiangolo.com โ€บ virtual-environments
Virtual Environments - FastAPI
When you work with Python projects, you should use a virtual environment to isolate the packages installed for each project. For FastAPI projects, I recommend using uv to manage the project, its dependencies, and its virtual environment. Install uv using the official installation guide, and then create a project: $ uv init awesome-project --bare $ cd awesome-project $ uv add "fastapi[standard]"
๐ŸŒ
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. If you have access to either sh or ksh shell, then open up the terminal and ...
๐ŸŒ
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 - Python installed. Command-line access to the system. PATH is a system variable that specifies a list of directories in which the operating system looks for applications. The PATH value is a string of directories separated by colons (on Linux and macOS) or semicolons (on Windows).