The first thing that comes to mind is that python3 didn't automatically export its path. I think that adding

export PATH="/usr/bin/python3/bin:$PATH" 

to .bash_profile or .bashrc and restarting terminal could do the trick.

Answer from darxsys on Stack Overflow
🌐
Real Python
realpython.com › add-python-to-path
How to Add Python to PATH – Real Python
January 30, 2023 - You need to prepend the call to the Python executable with its relative path in the current folder (./) because otherwise you’ll invoke whichever Python is currently recorded on your PATH.
Discussions

ubuntu - How to set up Python path? - Unix & Linux Stack Exchange
I have uninstall anaconda2. but now when I run Python command in terminal it says "bash: /home/user/anaconda2/python: No such file or directory" now how can I set to Python when I have python 2.7 i... More on unix.stackexchange.com
🌐 unix.stackexchange.com
December 31, 2015
linux - How do I add Python to PATH? - Stack Overflow
ubuntu@ip:/$ whereis python python: ... can run 'python3' instead. How do I set Python so I can just call python in the terminal and so that other programs can use it?? ... You have to use export along with the path to the Python 3.6 directory. See How to set your $PATH variable in Linux... More on stackoverflow.com
🌐 stackoverflow.com
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
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
🌐
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 - alias python=python3 # Then run: source ~/.bashrc # or: source ~/.zshrcCode language: PHP (php) ... Both should return versions, not errors. You’re good to go! ... Sometimes using a tool like Anaconda or uv can help manage environments more cleanly. ... Knowing how to add Python to PATH is one of those behind-the-scenes skills that makes your dev life smoother, especially when installing it on new machines or dev environments based on Windows.
🌐
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."
Find elsewhere
🌐
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.
🌐
Edureka
edureka.co › blog › add-python-to-path
Add Python To Path | How To Add A Python Path | Edureka
December 5, 2024 - In our example above, we have added ... reads ;C:Python34. Once this is done, press OK and the path will be added to the specific location. Save all your actions and reboot your system for more effective performance. Moving on with this article on How To Add Python To Path, The steps for adding Path in Unix or Linux are fairly ...
🌐
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.
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.
    >>> 
    
🌐
Stack Overflow
stackoverflow.com › questions › 58651549 › how-do-i-add-python-to-path
linux - How do I add Python to PATH? - Stack Overflow
@martineau I did export PATH=$PATH:/usr/bin/python3.6 but it still complains that python isnt found... ... If you want the python interpreter in the 3.6 folder to run when you type python, then you'll need to create an alias as described in @Muni's answer — otherwise I think you can run it by explicitly typing python3. ... You can make Python3 as a default python writing into bash alias. Refer this article: Configure Python 3 as default on Ubuntu. ... Sign up to request clarification or add additional context in comments.
🌐
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!

Top answer
1 of 3
9

You're absolutely right, they use different PYTHONPATHs.

You can think of Python 2.x and Python 3.x as completely different programming environments. And yes, they store their packages in different locations.

To get numpy working, you can type:

sudo apt-get install python3-numpy

If you want to find out where exactly a package is kept, you can look at the module objects __path__ attribute:

>>> import numpy
>>> numpy.__path__
['/usr/local/lib/python3.5/site-packages/numpy']

You can also install python3-pip and then run pip3 install whatever to install packages for Python 3 with Pip, for packages that aren't available in Ubuntu as python3-whatever.

In case you're confused about the difference between distutils, setuptools, easy_install, pip and the rest, use pip. That's the cool one. :)

2 of 3
5

No, they use the same PATH. However, this problem isn't with the PATH.

Python 2 and Python 3 are sufficiently different that packages have to be written separately for both of them. You cannot use a package written for one with the other.

In Ubuntu, these modules are stored in different locations and are packaged separately - python-numpy for Python 2, python3-numpy for Python 3. If you want numpy with Python 3, install python3-numpy.

$ python3 -c 'import sys; print (sys.path)'
['', '/usr/lib/python3.4', '/usr/lib/python3.4/plat-x86_64-linux-gnu', '/usr/lib/python3.4/lib-dynload', '/home/muru/.local/lib/python3.4/site-packages', '/usr/local/lib/python3.4/dist-packages', '/usr/lib/python3/dist-packages']
$ python2 -c 'import sys; print (sys.path)'
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client']
🌐
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 - Useful for testing, but you'll want to make the change permanent to have Python consistently available. To add Python to your PATH permanently on Linux, you'll need to edit shell startup scripts.
🌐
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 ...
🌐
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
🌐
Milddev
milddev.com › how-to-add-python-to-path
Add Python to PATH Guide - MildDev
July 28, 2025 - Click "New" and add the full path to your Python install folder (e.g., C:\Python39\ and C:\Python39\Scripts\). Click OK on all dialogs and restart any open terminals. After this, opening a new CMD or PowerShell window and typing python --version ...