DEV Community

sravya-07
sravya-07

Posted on

How to resolve python command not found error in Linux

I had both python3.8 and python2.7 installed on a Linux system (Ubuntu in this case, but this solution should work for other flavours of Linux too), however running python --version gave a python: command not found response.
Screenshot of an Ubuntu terminal. Shows the output of python --version command. The Output is Command 'python' not found.

Steps to resolve:

  1. Verify if any version of python was installed on the system

    • I wanted to be sure that the system had some version of python installed. Using whereis python3 or whereis python2 command shows the versions and paths of python installed on the system. The output should look something like this Screenshot of Ubuntu terminal that shows the output of whereis python3 command. The output shows paths we can find python3
  2. If there is no version of python installed, install it using sudo apt-get install python3.8 or sudo apt-get install python<version> (use yum instead of apt-get for RHEL)

  3. cd to /usr/bin folder and create a symlink to the version of python you want to be invoked using the python command.
    Example:
    cd /usr/bin
    ln -s /usr/bin/python3.8 python

    Verify the if the symlink is created using ls -l python and verify if the python command works and is pointing to the right version of python using python --version.
    Screenshot of Ubuntu terminal that shows the output of python command. The output is Python 3.8.10

Discussion (0)