How To Fix Error Python Is Not Recognized As An Internal Or External Command Operable Program Or Batch File

The error message “python is not recognized as an internal or external command, operable program, or batch file” typically occurs when the Python executable is not found in the system’s PATH environment variable. This issue can be resolved by adding Python to the PATH or by reinstalling Python with the option to add it to the PATH during installation. Here’s how you can fix it.

1. Check if Python Is Installed.

  1. Open a command prompt (Windows) or terminal (macOS/Linux) and type the command `python` or `python –version`.
  2. If Python is installed correctly, it will display the installed version.
  3. If it’s not installed, download and install Python from the official website: https://www.python.org/downloads/

2. Add Python to the PATH (Windows).

  1. During the installation process, there is an option to “Add Python x.x to PATH.” Ensure that this option is selected.
  2. If you have already installed Python without this option, you can either reinstall Python with the option enabled ( refer to How To Install Python/Pip On Windows ) or manually add Python to the PATH.

2.1 Manually add Python to the PATH.

  1. Find the installation path of Python (e.g., C:\Python39), you can read the article How To Find Where Python Is Installed On Mac, Linux, And Windows to learn more.
  2. Open the Start menu, search for “environment variables” and select “Edit the system environment variables“.
  3.  Click the “Environment Variables” button.
  4. In the “System variables” section, find the “Path” variable and click “Edit“.
  5. Click “New” and enter the path to the Python executable (e.g., C:\Python39) and click “OK” on all open dialogs.
  6. You can refer to the article How To Set Windows Environment Variables.

3. Restart Your Command Prompt Or Terminal.

  1. After making changes to the PATH environment variable, you must close and reopen any open command prompt or terminal windows for the changes to take effect.

4. Verify Python Is Recognized.

  1. Open a new command prompt or terminal and type `python –version` to check if Python is now recognized and displays the installed version.

5. macOS and Linux.

  1. If you’re using macOS or Linux, the steps are similar to adding Python to the PATH on Windows.
  2. However, macOS and most Linux distributions usually come with Python preinstalled. If you have issues, check your system’s Python installation and the PATH variable.
  3. You can first read the article How To Find Where Python Is Installed On Mac, Linux, And Windows to get your Python installed directory on your OS.
  4. Then add the Python installed folder such as /usr/local/bin to the macOS or Linux PATH system environment variable.
  5. You can read the article How To Change System Environment Variable Path Value On macOS & Linux Permanently to learn more.
  6. After following these steps, you should no longer encounter the “Python is not recognized” error, and you’ll be able to run Python commands from the command prompt or terminal.

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.