How to Fix 'python: command not found' Step by Step

Terminal window showing the 'python: command not found' error next to labels for PATH, python.org, Terminal and venv

The 'python: command not found' error means your terminal can't find the Python program when you type python. It's one of the most common first problems in programming, and it's very fixable. In nearly every case, Python isn't broken. The terminal simply doesn't know where to look.

This guide takes you from that error message to a setup you understand and can trust. The goal is simple: you open any terminal on Windows, macOS or Linux, type one short command, and the Python version you installed replies instead of an error. You need permission to install software and access to python.org. You don't need any coding experience.

In short
  • The error usually means Python's install folder isn't in your PATH.
  • Diagnose it with python --version and python3 --version, then locate Python with where or which.
  • Reinstall from python.org with 'Add Python to PATH' ticked, then open a fresh terminal.
  • Give each project its own virtual environment so your setup stays predictable.
  1. 0:00Intro
  2. 0:29Get Python answering in your terminal
  3. 1:10Recognise the command not found error
  4. 2:00Understand how PATH finds programs
  5. 2:39Check the Add to PATH box
  6. 3:32Run the version check
  7. 4:23Locate where Python lives
  8. 5:16Inspect the folders in your PATH
  9. 6:07Reinstall Python with PATH ticked
  10. 6:59Reopen your terminal to load PATH
  11. 7:39Create a virtual environment
  12. 8:35Activate it and keep projects separate
  13. 9:18Confirm Python and venv work
  14. 10:11Fix the most common errors
  15. 10:57Remember these key steps
  16. 11:19Check PATH first, every time

Recognise the 'command not found' error

You type python, press Enter, and the terminal acts as though it has never heard of it. On macOS and Linux the message says command not found. On Windows it says python is not recognised. Either way, the terminal searched every place it knows and found nothing. This can happen even when you've just installed Python and can see it in your apps.

There is a second, sneakier form of the same problem. Python starts, but it's an older copy from your system or an earlier install, not the one you just downloaded. It looks like a different issue, but both symptoms share one hidden cause. Knowing which symptom you have is already half the fix.

  • Symptom A: the terminal reports that python can't be found or isn't recognised
  • Symptom B: Python starts, but the version is older than the one you installed

Understand how PATH finds programs

PATH is a list of folders your terminal checks, in order, whenever you type a command. It does not search your whole computer. When you type python, it checks the first folder, such as /usr/bin, then the next, such as /usr/local/bin, then the next, such as ~/bin. If Python lives in a folder that isn't on the list, the search ends with command not found.

So the root cause is that Python's install folder was never added to PATH. That's good news. Python is installed correctly. The terminal just hasn't been told where it is, and that is something you can fix in a few minutes.

On Windows, the usual cause is one checkbox. The installer's first screen has an option called Add Python to PATH, and it's often left unticked. It sits below the large Install Now button, so many people click past it. macOS and Linux have no checkbox, but they have a related problem. Many of these systems only provide the command python3, so typing plain python fails even though Python is installed.

  • On Windows, look for 'Add Python to PATH' before you click Install Now
  • On macOS and Linux, try python3 as well as python

Run the version check

Before you change anything, gather evidence. Open your terminal. That can be PowerShell, Command Prompt, or Terminal on a Mac. Type python --version and press Enter. If you get an error, try python3 --version. Often one works when the other doesn't, especially on macOS and Linux.

This one command answers two questions. Can the terminal find Python at all? If it can, which version answered? A version number means Python is on your PATH, so check that it matches the version you downloaded. An older number means you have the wrong-version problem. If both commands fail, Python isn't reachable from PATH. Write down which commands failed and what they printed, because you'll use that information later.

  • A version appears: Python is on PATH, so compare the number with what you installed
  • An error appears: note which command failed and copy the exact message
# Try the plain name first
python --version
# If that fails, try python3
python3 --version

Locate where Python lives

Knowing that Python answers is not the same as knowing where it's coming from. This matters most when the wrong version runs, because you may have more than one Python installed. The commands in this step show the exact file the terminal runs. It's like asking for someone's full address instead of just knowing that somebody answered the door.

On Windows, open Command Prompt and type where python. On macOS or Linux, type which python3. In PowerShell, plain where is a different built-in command, so type where.exe python instead. If nothing appears, Python isn't on your PATH. If several paths appear, read them from the top, because the first one listed is the one that runs. An older Python listed above your new one explains why the wrong version keeps starting.

  • No result: Python isn't on PATH
  • Several results: the first path listed is the one that runs
  • In PowerShell, use where.exe, not where
# Windows (Command Prompt)
where python
# macOS and Linux
which python3

Inspect the folders in your PATH

PATH is just text: one long line of folder names joined together. Printing it lets you confirm the root cause instead of assuming it. On macOS or Linux, type echo $PATH, with PATH in capitals. In PowerShell, type $env:Path. On macOS and Linux the folders are separated by colons. On Windows they are separated by semicolons.

Scan the output for a folder name that includes the word Python, often followed by a version number. If you find one, PATH is probably fine. If you don't, you've confirmed what's missing. You may be tempted to fix PATH by editing it yourself. As a beginner, don't. One wrong character can break other commands. The reinstall in the next step updates PATH safely for you.

# macOS and Linux
echo $PATH
# Windows PowerShell
$env:Path

Reinstall Python with Add to PATH ticked

For beginners, the most reliable fix is a clean reinstall from the official site. That may sound drastic, but it's quick and safe. Your project files aren't touched, and the installer writes the correct folder into your PATH automatically. Download the installer for your system from python.org only. Other download sites can bundle unwanted extras.

Run the installer. On Windows, tick Add Python to PATH at the bottom of the first screen, then click Install Now. On macOS, follow the installer through to the end. Then close every terminal window, including any terminals inside code editors.

Closing your terminals is the step people most often skip. A terminal reads PATH once, when it starts, and keeps its own copy. The installer's update never reaches windows that were already open. If you test in one of them, it will look as though the fix failed. Test in a newly opened terminal instead. If you're still unsure, restart your computer so every program picks up the new PATH.

  • Download the installer from python.org only
  • On Windows, tick 'Add Python to PATH' before you click Install Now
  • Close every terminal, including the ones inside code editors
  • Test in a newly opened window, or restart if you're unsure

Create and activate a virtual environment

Python now runs, and this step helps keep it that way. A virtual environment is a private Python setup inside one project folder, like giving each project its own toolbox. Packages you install for one project stay inside that project, so they can't clash with other projects or with your system Python.

Move into your project folder and type python -m venv .venv. On macOS and Linux, use python3 instead of python. A new .venv folder will appear. The -m option tells the exact Python you typed to run its built-in venv module, so you always know which version the environment uses. Create one environment per project. That way, upgrading a package for a new project can never break an old one.

Creating the environment isn't quite enough, because you also need to activate it. Activation works by changing PATH. It temporarily puts the environment's folder at the front of PATH, so typing python finds the project's own copy first. When you close the window, everything returns to normal. While the environment is active, its name appears at the start of your prompt.

  • Activate on macOS/Linux: source .venv/bin/activate
  • Activate on Windows: .venv\Scripts\activate
  • Create one environment per project, not one shared by every project
# Go into your project folder
cd my-project
# Create a venv named .venv
python -m venv .venv

Confirm Python and venv work

Open a new terminal, activate your environment, and run three quick checks. Together they confirm that Python is found, that it's the right copy, and that your environment is the one being used. If all three pass, you know your setup works properly and didn't just work by chance.

First, check that the version number matches what you installed. Next, run where or which, and check that the path points inside your project's .venv folder. Finally, run a one-line print command so Python actually does something. If a check looks wrong, don't reinstall straight away. Note which check failed and what it printed, because that detail tells you which fix to try.

  • The version number matches what you installed
  • where or which shows a path inside .venv
  • The print command displays 'It works!'
python --version
where python      # Windows
which python      # macOS/Linux
python -c "print('It works!')"

Fix the most common errors

Even when you follow every step carefully, a few errors come up again and again. Most of them trace back to PATH or to a terminal that was opened before the change, so check those first. Find the error below that matches what you see on screen.

If your error isn't listed, copy the exact message into a search engine. Python is very widely used, so someone has almost certainly had the same problem and solved it. Treat error messages as clues that point you to the next step.

  • python: command not found: reinstall with Add to PATH ticked, then open a new terminal
  • Windows opens the Microsoft Store: turn off the app execution aliases for python
  • An old version answers: find every copy with where or which and check which is listed first
  • PowerShell blocks activation: change PowerShell's execution policy

Key takeaways

  • 'Command not found' means PATH can't see Python. It doesn't mean Python is broken.
  • Diagnose with python --version and python3 --version before changing anything.
  • Use where python or which python3. The first path listed is the one that runs.
  • Reinstall from python.org with 'Add Python to PATH' ticked instead of editing PATH yourself.
  • Always test in a new terminal, because old windows keep the old PATH.
  • Give each project its own virtual environment.

Frequently asked questions

Why does my terminal say python command not found when Python is installed?

The terminal only searches the folders listed in PATH, not your whole computer. If Python's install folder was never added to PATH, the terminal can't find it, even though Python is installed correctly.

Should I type python or python3?

It depends on your system. Many macOS and Linux systems only provide python3, so plain python fails there. If one command gives an error, try the other.

Why does typing python open the Microsoft Store on Windows?

Windows has app execution aliases that can send the python command to the Microsoft Store. Turning off the aliases for python stops this, so the Python you installed can answer instead.

I reinstalled Python but still get the error. What went wrong?

Most likely you tested in a terminal that was open during the install. A terminal reads PATH only once, when it starts. Close every terminal window, open a new one, or restart your computer if you're unsure.

Is it safe to edit PATH by hand?

It's possible, but as a beginner it's easy to make a mistake, and one wrong character can break other commands. Reinstalling from python.org with 'Add Python to PATH' ticked updates PATH safely for you.

Do I really need a virtual environment for every project?

It's the best habit to build early. Each environment keeps its own packages, so upgrading something for a new project can't break an old one, and you always know which Python a project uses.

Watch the full video on YouTube →

Souy Soeng

Souy Soeng

Hi there 👋, I’m Soeng Souy (StarCode Kh)
-------------------------------------------
🌱 I’m currently creating a sample Laravel and React Vue Livewire
👯 I’m looking to collaborate on open-source PHP & JavaScript projects
💬 Ask me about Laravel, MySQL, or Flutter
⚡ Fun fact: I love turning ☕️ into code!

Post a Comment

CAN FEEDBACK
Ad