Python Error Resolution With "Python Command Not Found" In Linux (2024)

Python, with its approachable syntax, straightforward semantics, and extensive lineup of frameworks and libraries, is often the preferred solution for data science projects and scripting requirements. It finds widespread applications in various fields, such as web development, analytics, machine learning, and data science.

However, many users encounter the python command not found error in a Linux environment, especially when they freshly set up a Python environment.

Table of Contents

  1. What Leads to the python: command not found Error?
  2. How to Resolve python: command not found Error in Linux
    1. Prerequisites
    2. Step #1: Install Python
      1. How to Install Python on CentOS
      2. How to Install Python on Rocky Linux
      3. How to Install Python on Ubuntu
      4. How to Install Python on Debian
      5. How to Install Python on ArchLinux
      6. How to Install Python on Fedora
    3. Step #2: Verify the PATH Variable
    4. Step #3: Verify Python Symbolic Links
  3. Conclusion
  4. FAQs

What Leads to the python: command not found Error?

In general, this error occurs when the operating system fails to locate the Python executable file and thus cannot execute Python commands or scripts.

The most common reasons for getting the error are:

  • Python isn’t installed on your computer.
  • The PATH setting doesn’t point to where Python is located.
  • The Python shortcut or link isn’t set up correctly.

To resolve the python: command not found error:

  • Check if Python is installed (Install it if it’s missing).
  • Update where Python is located by adjusting the PATH.
  • Make sure the correct Python version is used by adding or adjusting symbolic links.

How to Resolve python: command not found Error in Linux

We’ll now discuss the details of resolving this critical error. We’ll start with a short overview of installing Python on popular Linux distributions because the error pops up when the system can’t find an active Python installation.

Let’s see the prerequisites of the process:

Prerequisites

  • Terminal or command line access.
  • A user account with root or sudo privilege.

Step #1: Install Python

The quickest way to see if Python is on your computer is to check the version information. For this, just type this command in the terminal:

# python3 –version.

Python Error Resolution With "Python Command Not Found" In Linux (1)

The terminal shows the Python version number if Python is installed and available on your system. In this instance, the Python version is displayed as 3.6.8.

Alternatively, if Python is not installed on your machine, the version command will fail, and you will see the python: command not found error message.

Python Error Resolution With "Python Command Not Found" In Linux (2)

Python Error Resolution With "Python Command Not Found" In Linux (3)

How to Install Python on CentOS

To install Python on CentOS, follow these steps:

Open the command line and use the dnf package manager to update the list of packages in CentOS:

# yum update

Python Error Resolution With "Python Command Not Found" In Linux (4)

Next, use this command to install Python 3 on your CentOS system:

# yum install python3 -y

Python Error Resolution With "Python Command Not Found" In Linux (5)

How to Install Python on Rocky Linux

To set up Python on Rocky Linux, follow these steps:

Launch a terminal window and refresh the list of packages in Rocky Linux:

#dnf update -y

Python Error Resolution With "Python Command Not Found" In Linux (6)

Next, use this command to install Python 3 to your Rocky Linux system:

#dnf install python3 -y

Python Error Resolution With "Python Command Not Found" In Linux (7)

Next, verify the Python installation by checking the version information with the following command:

#python3 –version

Python Error Resolution With "Python Command Not Found" In Linux (8)

How to Install Python on Ubuntu

To get Python on Ubuntu, launch the terminal and refresh the list of Ubuntu packages:

# apt update -y

Python Error Resolution With "Python Command Not Found" In Linux (9)

Next, run this command to add Python 3 on Ubuntu:

#apt install python3 -y

Python Error Resolution With "Python Command Not Found" In Linux (10)

Verify the Python version to make sure it’s installed correctly.

# python3 –version

Python Error Resolution With "Python Command Not Found" In Linux (11)

How to Install Python on Debian

To install Python on Debian, follow these steps:

Open the terminal and refresh the list of Debian packages.

#apt-get update

Python Error Resolution With "Python Command Not Found" In Linux (12)

Next, run the following command to install Python 3 on your Debian system:

# apt install python3 -y

Python Error Resolution With "Python Command Not Found" In Linux (13)

Make sure Python is installed correctly by opening the Python 3 interactive shell.

Python Error Resolution With "Python Command Not Found" In Linux (14)

To leave the Python shell, press Ctrl+D.

How to Install Python on ArchLinux

To install Python on Arch Linux, you can use the package manager Pacman, which makes the process quite straightforward. Here are the steps to install Python on Arch Linux:

Launch the terminal and update the package index to ensure you have the latest information about available packages.

# pacman -Syu

Next, install Python with the following command:

# pacman -S python

This will install the latest version of Python 3 available in the Arch Linux repositories.

After the installation is complete, you can verify the Python installation by running the following command:

# python –version

How to Install Python on Fedora

Installing Python on Fedora is a straightforward process using the DNF package manager, which is the default package manager on Fedora.

Launch the terminal and update the package index with the following command:

# dnf update

Next, install Python 3 with the following command:

# dnf install python3

This command will install the latest version of Python 3 available in the Fedora repositories.

After the installation is complete, you can verify the Python installation by running the following command:

# python3 –version

Step #2: Verify the PATH Variable

The PATH is like a list of places the computer looks for programs. It uses this location as an index of the actual program location. After installation, you should make sure that the PATH contains an entry for Python.

For this, print out the PATH contents with the following command:

# echo $PATH.

The result should show the location where Python is installed.

Python Error Resolution With "Python Command Not Found" In Linux (15)

If the computer doesn’t know where Python is, you can tell it where to find it by manually adding the path to Python’s installation.

For this, open the .bashrc file in your preferred text editor. We’ll use vi for this demonstration:

# vi ~/.bashrc

Add this line to the end of the .bashrc file:

export PATH=”$PATH:/python/path/executable/”

Python Error Resolution With "Python Command Not Found" In Linux (16)

Swap /python/path/executable/ with the actual directory path where Python is located on your computer.

Save the file and then close the editor.

Next, use the following command to make the changes take effect:

# source ~/.bashrc

As a good measure, close and reopen the terminal.

To double-check if the PATH is updated, use the echo command:

# echo $PATH

Python Error Resolution With "Python Command Not Found" In Linux (17)

Step #3: Verify Python Symbolic Links

Symbolic links, or symlinks, are like signposts that guide to other files or folders. They’re handy for making shortcuts or nicknames for Python programs.

When you have several Python versions, symlinks help you decide which one to use when you type a command.

You can view the list of Python symlinks with the following command:

# ls -l /python/path/executable.

Put in the actual path to your Python folder instead of /python/path/executable

This command shows information about the Python program file and shows shortcut links. For instance, if files are in the ./python3.11 folder, you can use python3 to run them.

Python Error Resolution With "Python Command Not Found" In Linux (18)

You should make a new symlink to allow users to use the python command for running Python 3.

# ln -s /usr/bin/python3 /usr/bin/python

Similarly, you can delete symlinks that are not being used or broken with the rm command:

# rm /usr/bin/python

Also Read: How to Install Rust on Ubuntu 20.04/22.04

Also Read: Add Elements to Python Array: 3 Methods Inside!

Conclusion

You might see python: command not found error, especially if you have freshly installed Python on a system, or the PATH doesn’t contain the right information.

The best way of avoiding this error is to install Python the right way is the easiest way of avoiding this error. We covered the proper process of installing Python on all popular Linux distributions.

We also discussed the critical steps about setting the PATH and symlinks to ensure smooth performance for Python applications.

If you’re looking for a robust server for your Python projects, RedSwitches offers the best dedicated server pricing and delivers instant dedicated servers, usually on the same day the order gets approved. Whether you need a dedicated server, a traffic-friendly 10Gbps dedicated server, or a powerful bare metal server, we are your trusted hosting partner.

FAQs

Q. What is the cause of the python: command not found error in Linux Ubuntu?

The python: command not found error occurs when the system cannot find the Python interpreter in the specified path.

Q. How do I install Python on Linux Ubuntu?

To install Python on Linux Ubuntu, you can use the following command: sudo apt-get install python

Q. How do I check if Python is installed on my system?

You can check if Python is installed on your system by typing the following command in your terminal: python –version

Q. What should I do if I see the python: command not found error?

To resolve the python: command not found error in Linux, you can try the following steps:

  1. Check if Python is installed by running the command python –version
  2. If Python is not installed, install it using the command sudo apt-get install python
  3. If Python is already installed, check the PATH variable to ensure it includes the directory where Python is installed.
  4. If the PATH variable is correct, check if there is a broken symlink for Python by running the command ls -l $(which python)
  5. If there is a broken symlink, remove it by running the command sudo rm $(which python) and then create a new symlink using the command sudo ln -s $(which python3) /usr/bin/python

Q. How do I configure the Python PATH variable in Linux Ubuntu?

To configure the Python PATH variable in Linux Ubuntu, you can follow these steps:

  1. Open the terminal
  2. Edit the ~/.bashrc file using a text editor
  3. Add the following line to the file: export PATH=$PATH:/path/to/python (replace /path/to/python with the actual path to your Python installation)
  4. Save the file and exit the text editor
  5. Run the command source ~/.bashrc to apply the changes

Q. How can I check the Python path on Linux Ubuntu?

You can check the Python path on Linux Ubuntu by executing the command in python

Q. Can I use Python 3 instead of Python 2?

Yes, you can use Python 3 instead of Python 2. In recent versions of Ubuntu (e.g., Ubuntu 18.04 and Ubuntu 20.04), the Python command is linked to Python 3 by default.

Q. How do I fix the python: command not found error in Ubuntu 18.04?

To fix thepython: command not found an error in Ubuntu 18.04, you can use the following command to create a symlink: sudo update-alternatives –install /usr/bin/python python /usr/bin/python3 1

Q. What should I do if Python is installed but still getting the python: command not found error?

If Python is installed, but you still get the python: command not found error, you can try using the command python3 instead of python to execute your Python scripts.

Q. How do I run Python commands in Linux?

To run Python commands in Linux, open a terminal and type python or python3 (depending on your installed version). This will launch the Python interpreter, where you can execute your commands.

Python Error Resolution With "Python Command Not Found" In Linux (2024)

FAQs

Python Error Resolution With "Python Command Not Found" In Linux? ›

In conclusion, resolving the “Python Command Not Found” error in Linux involves checking whether Python is installed, verifying the Python executable's path in the system's PATH variable, and installing Python if necessary.

How to fix Python command not found in Linux? ›

To fix the python: command not found error:
  1. Verify the Python installation and install Python if necessary.
  2. Edit PATH variable to include the Python executable path.
  3. Add or modify symbolic links to ensure correct Python version usage.
Jul 13, 2023

What is error command not found in Linux? ›

This error often occurs when the system cannot find the specified file in the path variable. However, there are effective solutions to overcome this error, including installing missing packages, explicitly specifying paths, modifying the path variable, and ensuring accurate command spelling.

How do you check whether Python is installed or not in Linux? ›

Open a terminal:

Launch the terminal application on your Linux system. You can typically find it in the applications menu or by using a keyboard shortcut such as Ctrl+Alt+T. This command will display the Python version installed on your system.

How to install Python in Linux terminal? ›

Step by Step Guide to Install Python on Linux
  1. Step 1 - Install Development Packages Required to Install Python on Linux- ...
  2. Step 2 - Download the Latest Version of Python.
  3. Step 3 - Extract the tar file to install Python on Linux.
  4. Step 4 - Configure the Script.

How do I resolve a command not found in Linux? ›

5 ways to fix "Command not found" errors
  1. Include the path. Not everything you want to execute needs to be in your path. ...
  2. Add a new path. Alternately, you can add a new directory to your PATH. ...
  3. Copy a file to an existing path location. ...
  4. Tell Bash where to look. ...
  5. Install a package.
Apr 20, 2022

How to use Python command on Linux? ›

Want to know how to run Python script in Linux, follow these steps:
  1. Open a Terminal: Launch the Terminal application on your Linux system. ...
  2. Navigate to the Script's Directory: Use the cd command to navigate to the directory where your Python script is located. ...
  3. Make the Script Executable: ...
  4. Run the Script:
Jun 5, 2024

How do I resolve errors in Linux? ›

To resolve the filesystem errors on an Linux/Ubuntu server that prevent writing to the server, follow these steps:
  1. Reboot the server. If it stops at initramfs, this indicates a filesystem error.
  2. Go to the start terminal and enter the following command: fsck /dev/disk -y.
  3. After a few seconds, the server can be restarted.
Nov 24, 2023

Why does my terminal keep saying command not found? ›

One of the most common reasons for the command not found error is incorrect syntax. Even a small typo can cause this frustrating issue. To fix it, carefully check and review the command you entered, looking for any spelling errors or mistakes in the syntax.

How to check error in Linux command? ›

The fsck (File System Consistency Check) Linux utility checks filesystems for errors or outstanding issues. The tool is used to fix potential errors and generate reports. This utility comes by default with Linux distributions. No specific steps or an installation procedure is required to use fsck.

How do I know if a Python program is running Linux? ›

Using the ps Command

The ps command is a powerful tool that provides information about the running processes. Moreover, this command, along with other helper commands such as grep, can identify and earmark the Python processes in particular. First, ps -ef retrieves a list of all running processes in detail.

What is the command to check Python version in Linux? ›

To check the Python version on Linux, you can open the terminal and type python –version or python -V.

How to check if Python is working? ›

Check if It's Working: Open a new terminal and type python or python3 . It should start the Python interpreter. The default is in c:\program files\python something these days.

How to fix Python command not found? ›

This error occurs when python is not a shell command. The solution is to correctly install Python and set the Mac PATH. But first you need to think about why you are trying to run Python because the solution depends on whether you are running a Python program or developing a Python project.

How to install Python 3.10 in Linux? ›

  1. Prerequisite. sudo apt update sudo apt install software-properties-common -y.
  2. Add custom APT repository. sudo add-apt-repository ppa:deadsnakes/ppa sudo apt update. ...
  3. Install Python 3.10. ...
  4. Install PIP for Python 3.10. ...
  5. Test with system ENV. ...
  6. Test with Virtual ENV. ...
  7. References.

How to install Python 3.9 in Linux? ›

  1. Enable the CodeReady Linux Builder repository: # subscription-manager repos --enable codeready-builder-for-rhel-9-x86_64-rpms. subscription-manager repos --enable codeready-builder-for-rhel-9-x86_64-rpms.
  2. Install the python3*-Cython package: For Python 3.9: # dnf install python3-Cython. dnf install python3-Cython.

How do I fix a Python module not found? ›

How to fix the ModuleNotFoundError in Python
  1. Make sure imported modules are installed. Take for example, numpy . ...
  2. Make sure modules are spelled correctly. ...
  3. Make sure modules are in the right casing. ...
  4. Make sure you use the right paths.
Sep 12, 2022

How do I fix Python is not installed? ›

Environment
  1. If Python* is not yet installed: Install Python and during installation, select the checkbox option add python to PATH.
  2. If Python is already installed, add Python path to the environment variables path, as follows: ...
  3. If symptoms persist, uninstall and reinstall Python.

How do I enable Python commands? ›

To run Python in CMD Windows 10, first ensure that Python is installed and added to your system's PATH. Open CMD, type python , and press Enter. This will open the Python interactive shell in the command line.

Why does terminal say command not found in Python? ›

Possible reasons for this error: You need to restart your Terminal ("reset the shell"). A system Python is installed but not in the $PATH . A newer Python version is installed but not in the $PATH .

Top Articles
Repair or replace your laptop: 5 things to consider | Asurion
ETF vs FOF - Differences and Which is Better Option
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Pearson Correlation Coefficient
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Nfsd Web Portal
Selly Medaline
Latest Posts
Article information

Author: Greg Kuvalis

Last Updated:

Views: 5675

Rating: 4.4 / 5 (55 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Greg Kuvalis

Birthday: 1996-12-20

Address: 53157 Trantow Inlet, Townemouth, FL 92564-0267

Phone: +68218650356656

Job: IT Representative

Hobby: Knitting, Amateur radio, Skiing, Running, Mountain biking, Slacklining, Electronics

Introduction: My name is Greg Kuvalis, I am a witty, spotless, beautiful, charming, delightful, thankful, beautiful person who loves writing and wants to share my knowledge and understanding with you.