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

ubuntu - How to set up Python path? - Unix & Linux Stack Exchange
If you are just looking for python ... use that path. For troubleshooting and setting PYTHONPATH see this link: https://stackoverflow.com/questions/18247333/python-pythonpath-in-linux ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... 0 /usr/bin/python: bad interpreter: No such file or directory (Removed python rpms now python doesn't work and yum doesn't work) ... Add two rational ... 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
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
python - PYTHONPATH on Linux - Stack Overflow
PYTHONPATH is an environment variable those content is added to the sys.path where Python looks for modules. More on stackoverflow.com
🌐 stackoverflow.com
🌐
Tutorialspoint
tutorialspoint.com › python › python_environment.htm
Python - Environment Setup
To add the Python directory to ...ocal/bin/python" and press Enter. In the bash shell (Linux) − type export PATH="$PATH:/usr/local/bin/python" and press Enter....
🌐
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 - 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.
🌐
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
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.
    >>> 
    
🌐
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."
🌐
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:
🌐
Reddit
reddit.com › r/linux4noobs › adding python scripts to $path variable without having to use “python3 script.py”
r/linux4noobs on Reddit: Adding python scripts to $PATH variable without having to use “Python3 script.py”
July 29, 2020 -

So, I started writing a few python scripts to do odd jobs such as encoding/decoding base64 strings, identifying hashes etc. I put these scripts in my /home/scripts directory.

My question is, I want these scripts to be able to run in the terminal as commands without having to use something like “Python3 script.py ... “.

I have tried adding them to the $PATH variable and altering the .bashrc and .profile file, however I still have to run them through the python file.

Short of writing a bash script to middle man the commands, is there any easy ways to do this?

If this isn’t the correct sub, just let me know and I will change the post.

Thanks!

🌐
Codidact
linux.codidact.com › posts › 287333
Adding Python 3.11 to `$PATH` - Linux Systems - Codidact
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.
🌐
Eyesopen
docs.eyesopen.com › toolkits › python › quickstart-python › linuxosx_pythonpath.html
PYTHONPATH Installation — Toolkits -- Python
PYTHONPATH=/usr/local/OpenEye-toolkits-python3-linux-x64-|pypkgversion| export PYTHONPATH · The syntax and location may vary if you use a shell other than bash. The equivalent can be done in Python code as follows: $ python ... >>> import sys >>> sys.path.append("/usr/local/OpenEye-toolkits-python3-linux-x64-|pypkgversion|")
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.

🌐
Plain English
python.plainenglish.io › how-to-add-python-to-path-on-linux-and-macos-c4306985540
How to Add Python to PATH on Linux and macOS | by abdulazeez sherif | Python in Plain English
August 13, 2024 - It’s similar to the following operation in Python: >>> PATH = "/home/sifusherif/apps:/bin" >>> PATH = f"/home/sifusherif/python:{PATH}" >>> PATH '/home/sifusherif/python:/home/sifusherif/apps:/bin' Now refresh your current command-line session with this command, replace .profile with the login script you choose: ... when next you log in, Python should automatically be added to PATH you can now call python directly from the command line.
🌐
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 - 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: ... Now check if Python commands work properly from any directory, and enjoy the convenience! In some cases, you may find that even after adding Python to PATH, commands still fail to run properly from different directories.
🌐
Super User
superuser.com › questions › 588417 › howto-install-a-python-app-and-add-it-to-path-in-linux
command line - Howto install a python app and add it to path in Linux? - Super User
April 27, 2013 - I think this happens because the workingdir is the path of the link. create a bash script, set the working dir, start the python script and pass the cmd arguments ... The easiest thing would be to simply add the directory where you have the ...