python command not found

Python Command Not Found: What Is The Solution?

Tech & Innovation 30 November 2023 5 Mins Read

“Python command not found” is an error that occurs when your system is unable to find the Python executable file. This prevents Python users from executing Python commands and scripts. Python is a popular programming language, and it is known for its user-friendly syntax, large collections of libraries, frameworks, and semantics. The programming language has extensive use in analytics, machine learning, web development, and data science.

In this article, you will learn about how to solve the Python error named “Python: command not found” on your Linux system. We will discuss the error and the cause of the error. Next, we will also discuss how to install Python in the right manner so that the error does not occur. Finally, we will also share two other methods which you can use to solve the problem.

What Is The Python Programming Language? – A General Overview

What Is The Python Programming Language – A General Overview

Python.org states –

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built-in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together.”

Python is one of the most popular programming languages and has huge applications in data science, machine learning, web development, and analytics. Programmers prefer this programming language due to its simple syntax, easy-to-learn semantics, and huge portal of libraries and frameworks.

According to GeeksForGeeks.org,

Python is a lot easier to code and learn. Python programs can be written on any plain text editor like Notepad, Notepad++, or anything of that sort. One can also use an online IDE for writing Python codes or can even install one on their system to make it more feasible to write these codes because IDEs provide a lot of features like intuitive code editor, debugger, compiler, etc.

What Is The “Python Command Not Found” Error?

However, once you have set up your Python environment in your computer system, you might encounter the “Python: command not found” error. This error is most common in Linux systems. Here, your operating system is unable to locate the Python executable file in your system. Hence, you will not be able to execute scripts and commands in Python.

What Is The Cause Of Error?

What Is The Cause Of Error

This error occurs when the operating system (in your case, PC or Linux) fails to find the Python executable file. As a result, the system cannot execute Python scripts and Python commands.

There can be a variety of causes for the occurrence of the error: “Python: command not found”. Here are the three common causes:

  • It can occur since Python is not installed in the system.
  • The PATH variable in Python might not contain the Python executable file.
  • The Python symbolic link does not have the correct configuration.

These solutions are for the Python 3 version, as the previous versions are discontinued. Hence, while giving solutions to the problems, we are considering that you must use Python 3.

If you want to resolve the “Python: command not found” error, you will need to do the following things:

1. Check whether the Python installation is correct in your system or not.

2. Adjust the PATH and update where Python is located in your system.

3. Add or adjust symbolic links to Python to ensure that you are using the correct version of Python.

How To Solve “Python Common Not Found” Error?

To resolve the “Python: command not found” error, you will need to have some prerequisites. You have to ensure that there is a terminal or command line access to your system (It is a command prompt in PC). Since this problem is common in Linux systems, we are offering solutions for Python in Linux.

Here are the three things that you need to ensure to resolve “Python: command not found”:

1. Checking Your Python Installation On Linux

The first method is to check whether your system consists of Python or not. To do that, consider using the following command in your terminal:

Python3 –version

It will show the Python version, let’s say, Python 3.11.5. This is the version number of Python that you are using in your Linux system.

If your system does not consist of Python, it will not show the number. Rather, it will show you the same error…

bash: python: command not found

***In this case, if you want to install Python into your system, consider reading this article.

2. Check PATH Variable 

The PATH variable in Python is a list of directories on Python. Your operating system (OS) uses these directories to search executable files without providing the full path name of the file.

To check whether your Python executable directory is in the system’s PATH, consider using the following command:

echo $PATH

Make sure that the output to this command contains the path to the installation directory of Python. If your PATH variable does not contain the Python path, consider adding it manually:

Step 1: To do this, open your preferred text editor (in this article, we use ‘nano’). Access the .bashrc file.

sudo nano ~/.bashrc

Step 2: Next to the line, add this line:

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

Use your Python directory path on your system to replace the path in the command.

Step 3: Close the text editor after saving the file.

Step 4: Use this command:

source ~/.bashrc

This will apply to the changes.

Step 5: To complete the PATH update, restart the terminal.

Step 6: To confirm the addition of the new PATH variable, use the ‘echo’ command:

echo $PATH

3. Check Python Symbolic Links 

Symbolic links are provisional files. These files point to other files or directories. To create aliases or shortcuts for Python executables.

To list Python symlinks, enter the following command:

ls -l /path/to/python/executable

Use your Python directory path on your system to replace the path in the command.

The output of this command displays the details of the Python executable file. This includes the symbolic links as well.

You can create a new symlink if you want to enable users to make use of the Python command to run Python 3.

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

Now, you can utilize the ‘python’ command to run commands in Python 3. You can also consider using the rm command. This will remove unused or broken symlinks:

sudo rm /usr/bin/python

Wrapping Up

With the help of these three methods, you can successfully resolve the “Python: command not found” error. Use these three steps mentioned above, and you will be able to resolve the errors. First, verify the Python installation. Then, check the PATH variables and then modify Python symbolic links. Do you have more solutions to offer? Consider sharing your ideas with us in the comments section below.

Need More Business Related Articles Click Below!!

tags

python error python fix python help python not found python troubleshooting

A passionate writer and an avid reader, Soumava is academically inclined and loves writing on topics requiring deep research. Having years of content writing experience, Soumava also loves creating blogs in other domains, including digital marketing, business, technology, travel, and sports.

Leave a Reply

Your email address will not be published. Required fields are marked *

may you also read

Building Permit Software: Revolutionizing the Construction Process
Everything You Need To Know About J&T Express
Wearable Tech For Outdoor Activities