Python command not found” (Step-by-Step Guide)

You just installed Python, opened your terminal with excitement, and typed python. The result? An error message: “command not found” (or “is not recognized as an internal or external command“).

Well, your computer isn’t broken, and you didn’t necessarily install anything wrong. The problem is simply a “communication gap.” In this guide, we will teach your operating system how to find Python once and for all.


What does this error actually mean?

When you type a command in the Terminal (Windows, macOS, or Linux), the system searches for an executable file with that name in a list of specific folders called the PATH.

It means:

  1. Python is installed, but its folder is not in the PATH list.
  2. The command you typed is slightly different from what the system expects (e.g., python vs. python3).
  3. Python was not installed at all.

Step 1: Verify if Python is actually there

Before diving into settings, check if the issue is just the name of the command. In your terminal, try the following commands:

  • python3 --version
  • py --version (Windows exclusive)
  • python --version

If any of these return something like Python 3.x.x, Python is installed! Your only “problem” is knowing which shortcut name to use.

Step 2: Fixing it on Windows (The Easiest Way)

The most common reason for this error on Windows is forgetting to check a “magic box” during installation.

The Lazy and Effective Solution:

  1. Download the Python installer again from the official website.
  2. Run the installer and choose the Modify option (or uninstall and start over).
  3. CRITICAL: Check the box that says “Add Python to PATH” at the bottom of the window.
  4. Click Install or Modify.
  5. Close your terminal and open it again.

If you don’t want to reinstall (Manual Fix):

  1. In the Start menu, type “Environment Variables” and click “Edit the system environment variables”.
  2. Click the Environment Variables button.
  3. Under “System Variables,” find the line labeled Path and click Edit.
  4. Click New and paste the path where Python was installed (usually something like C:\Users\YourUsername\AppData\Local\Programs\Python\Python312).
    • Replace “YourUsername” with your actual profile name.
  5. Click OK on all windows and restart your terminal.

Step 3: Fixing it on macOS and Linux

On Mac and Linux, Python 3 is usually pre-installed, but the command python is often reserved for version 2 (which is outdated).

Use the correct command:

Try using python3 instead. If it works, your problem is solved!

Creating an “Alias”:

Do you want to type python and have the system understand it as python3? You can create a permanent alias:

  1. Open your shell configuration file (usually ~/.zshrc or ~/.bashrc).
  2. Add this line to the end of the file: alias python='python3'
  3. Save the file and type source ~/.zshrc (or .bashrc) in the terminal to apply the change.

Conclusion

The “Python command not found” error is just your computer saying it doesn’t know where you stored Python. Once you add the correct path to the PATH variable or use the python3 command, the problem disappears.

Expert Tip: When in doubt, always use Virtual Environments (venv) for your projects. This prevents you from messing up your system’s global settings and keeps your projects organized.


FAQ – Frequently Asked Questions

The py command triggers the "Python Launcher." This is a smart tool that automatically finds the latest version of Python installed on your Windows machine. It is the recommended way to run scripts on Windows.

Leave a Comment