How to Resolve "Python was not found; run without arguments to install..." Error
When attempting to run Python or related commands like pip
from the Windows Command Prompt (CMD) or PowerShell, you might encounter the error message: Python was not found; run without arguments to install from the Microsoft Store...
. This usually indicates that Windows cannot locate your Python installation via the system's PATH
environment variable, or that a conflicting "app execution alias" is interfering.
This guide explains the common causes of this error on Windows and provides step-by-step solutions to configure your system correctly.
Understanding the "Python was not found" Error
This error message means that when you typed python
into your command line, Windows searched through all the directories listed in your system's PATH
environment variable but couldn't find an executable file named python.exe
.
There are two main reasons for this:
- Python is not in the PATH: The directories containing
python.exe
and related scripts (likepip.exe
) were not added to thePATH
during installation or were removed later. This is the most common cause. - Python is not installed: Python might not be installed correctly or at all on your system.
- App Execution Alias Interference: Newer Windows versions have "App execution aliases" that might place a "stub"
python.exe
(which points to the Microsoft Store) earlier in the search order than your actual installation.
The error message often suggests installing Python from the Microsoft Store, which might not be what you intend if you've installed Python using the official installer from python.org.
Quick Solution / Workaround: Using the py
Launcher
Windows often comes with the Python Launcher (py.exe
) installed, which is usually added to the PATH correctly. It knows where your Python installations are (via the registry) and can run them even if python.exe
itself isn't directly on the PATH. Try using py
instead of python
in your commands:
:: Check Python version (via py launcher)
py --version
:: Start the Python interpreter
py
:: Exit the interpreter (type this inside Python)
exit()
:: Install packages using pip (via py launcher)
py -m pip install <package-name>
:: Run a Python script
py your_script.py
The py
launcher is also useful for managing multiple Python installations:
py -0
: Lists installed Python versions.py -3.9
: Runs the latest Python 3.9 installation.py -3.10 -m pip install ...
: Installs a package using Python 3.10's pip.
While py
is a great workaround, fixing the PATH (Solution 3) is often desirable so the standard python
command works as expected.
Primary Solution: Adding Python to the PATH Environment Variable
This ensures the python
command works directly.
Finding Your Python Installation Paths
You need two paths: the directory containing python.exe
and the Scripts
subdirectory (containing pip.exe
, etc.). Use the py
launcher to find them:
:: Find the main Python directory
py -c "import os, sys; print(os.path.dirname(sys.executable))"
:: Example Output: C:\Users\YourUser\AppData\Local\Programs\Python\Python310
:: Find the Scripts directory (usually just add \Scripts to the above path)
:: Example: C:\Users\YourUser\AppData\Local\Programs\Python\Python310\Scripts
Replace YourUser
and Python310
with your actual username and Python version.
Editing the PATH Variable (System Properties)
- Search: Windows search bar -> type "environment variables" -> click "Edit the system environment variables".
- System Properties: Click "Environment Variables...".
- User Path: In the top "User variables..." section, select
Path
and click "Edit...". (Editing User Path is usually sufficient and safer than System Path). - Edit List: Click "New".
- Add Python Dir: Click "Browse..." and navigate to the main Python directory you found in step 3.1 (e.g.,
C:\...Python\Python310
). Click "OK". - Add Scripts Dir: Click "New" again. Click "Browse..." and navigate to the
Scripts
subdirectory you found in step 3.1 (e.g.,C:\...Python\Python310\Scripts
). Click "OK". - Confirm: Click "OK" on all open dialog windows ("Edit environment variable", "Environment Variables", "System Properties").
Restarting Your Shell
Crucial Step: Close all open Command Prompt or PowerShell windows. Open a new one for the changes to take effect. Sometimes a full PC restart is needed.
Secondary Solution: Disabling App Execution Aliases
If adding Python to the PATH doesn't work, the Microsoft Store alias might be interfering.
- Search: Windows search bar -> type "Manage app execution aliases" -> open it.
- Find Aliases: Locate the entries for
python.exe
andpython3.exe
labeled "App Installer". - Disable: Toggle the switches next to these entries to "Off".
- Restart Shell: Close and reopen any CMD/PowerShell windows.
Fixing PATH Using the Python Installer
If manual editing is difficult or doesn't work, use the official Python installer.
Modifying an Existing Installation
- Find and run the original Python installer
.exe
file you downloaded. - Choose "Modify".
- Ensure "pip" is checked on the "Optional Features" screen. Click "Next".
- On the "Advanced Options" screen, check the box "Add Python to environment variables".
- Click "Install".
Reinstalling Python Correctly
- Consider uninstalling Python first via "Apps & features" (optional but cleaner).
- Download the installer from python.org.
- Run the installer.
- Important: On the very first screen, check the box "Add python.exe to PATH" (or similar wording).
- Choose "Install Now" or customize if needed.
Verifying the Fix
After applying a solution and restarting your shell, test the python
command directly:
python --version
python -m pip --version
python your_script.py
If these commands run without the "Python was not found" error, the issue is resolved. If you still get errors, try restarting your PC.
Configuring Your IDE (e.g., VS Code)
Remember that your Integrated Development Environment (IDE) like VS Code also needs to know which Python interpreter to use. If your terminal works but your IDE gives errors (or vice-versa), ensure the IDE's selected interpreter matches the one you configured in your PATH or the one managed by the py
launcher.
- In VS Code: Press
Ctrl+Shift+P
(orCmd+Shift+P
), type "Python: Select Interpreter", and choose the correct Python installation (it should now show the one added to PATH or found by thepy
launcher).
Conclusion
The "Python was not found..." error on Windows typically means the python
command isn't accessible via the system PATH
or is being overshadowed by Microsoft Store aliases. To fix it:
- Try using the
py
launcher as a quick workaround (py --version
,py -m pip ...
). - Add Python's installation and Scripts directories to your User PATH environment variable via System Properties (remember to restart your shell).
- Disable the App Execution Aliases for
python.exe
andpython3.exe
in Windows Settings. - Use the Python installer's "Modify" or "Install" options to ensure "Add Python to PATH" is correctly configured.
By ensuring Windows can find your python.exe
installation, you can run Python commands smoothly from your preferred shell.