This is, without a doubt, a common issue that many beginner programmers have encountered: “’python’ is not recognized as an internal or external command, operable program or batch file.” It happens for a simple reason: Windows does not know which folder contains the python.exe file.
When you type python in the Command Prompt (CMD) or PowerShell, Windows searches through a list of directories called Environment Variables. If your Python installation location is not on this list, the system returns the unrecognized command error.
Follow the steps below to fix it.
1. Locate where Python is installed
First, we need to find the exact installation address. If you installed Python using the default installer from the official website, it is usually located in a hidden folder.
- Press the Win + R keys, type
%AppData%, and hit Enter. - The
Roamingfolder will open. Go back one folder level to reach theLocalfolder. - Navigate through the following path: Programs > Python > Python3x (where
3xis your version, such asPython312). - Important: Copy the path that appears in the File Explorer address bar (e.g.,
C:\Users\YourName\AppData\Local\Programs\Python\Python312). - Also, save the path to the Scripts folder, which is located inside that same Python folder. You will need both.
2. Open System Environment Variables
Now that we have the addresses, we need to register them in Windows 11.
- Click the Start menu and type “Environment variables”.
- Select the option “Edit the system environment variables”.
- In the window that opens (System Properties), click the Environment Variables button at the bottom of the Advanced tab.
3. Configure the PATH
We will focus on User variables, which only affect your profile and are safer to modify.
- In the top section (User variables for [YourName]), locate the variable named Path and click Edit.
- In the new window, click the New button.
- Paste the first path you copied (the main Python folder).
- Click New again and paste the second path (the Scripts folder).
- Click OK to close the Path editing window.
- Click OK in the Environment Variables window and OK in the System Properties window.
4. Restart the Terminal
Changes to Environment Variables are not applied to terminal windows that are already open.
- Close any open instances of CMD or PowerShell.
- Open a new Command Prompt (or Windows Terminal).
- Type the following command and press Enter:DOS
python --version - If the system returns something like
Python 3.x.x, the error has been corrected.
Alternative: Fix via Installer
If you prefer not to manually edit system variables, you can use the installer to handle the process:
- Run the Python installer you downloaded from the official website (or download it again).
- On the initial screen, select the Modify option.
- Click Next on the optional features screen.
- On the Advanced Options screen, check the box “Add Python to environment variables”.
- Click Install or Modify. The installer will attempt to register the paths in the PATH for you.
Conclusion
Solving the “Python is not recognized” problem is an essential step in setting up your environment. By adding the Python and Scripts folders to the Windows 11 PATH, you ensure that the compiler works along with essential tools like pip.
Your operating system now knows exactly where to look for the necessary executables whenever you invoke a Python-related command.
FAQ
Qual a importância de adicionar a pasta "Scripts"?
A pasta Scripts contém o executável do pip (instalador de pacotes) e outras ferramentas que você instalará futuramente, portanto, faça passo a passo sobre o que eu disse, pois, sem ela no PATH, você conseguirá rodar o Python, mas não conseguirá instalar bibliotecas como Pandas, Flask ou Django facilmente pelo terminal.
Preciso reiniciar o computador?
Apenas fechar e abrir o terminal é o suficiente para que o Windows carregue as novas Variáveis de Ambiente. Caso o erro persista mesmo assim, uma reinicialização do sistema é recomendável.