Whether you’re writing your own Python code or running existing scripts on a Windows PC, this guide shows you how to run a Python file from the Windows Command Prompt. It’s a simple process once Python is installed, and you’ll also learn how to fix common errors like “python is not recognized as an internal or external command” or “Python was not found.”
How to run Python scripts from Command Prompt on Windows
Follow these detailed steps to execute your script or fix PATH issues if Python isn’t recognized.
Running your Python script
- Find the full path of your Python file:
- Open File Explorer.
- Navigate to the folder containing your Python file.
- Right-click the file and select Properties.
- Copy the path next to Location by highlighting it and pressing Ctrl + C.
- Open Command Prompt by pressing the Windows key, typing cmd, and selecting the app.
- Switch to the script’s directory by typing cd followed by a space, then pasting the full path with Ctrl + V and pressing Enter.
- Type python followed by the filename, such as python script.py, and press Enter to run it.
- If the filename contains spaces, enclose it in quotes, like python “my script.py”.
Adding Python to the PATH (if needed)
- Enable viewing of hidden folders in File Explorer:
- Click the View tab.
- On Windows 11, select Show > Hidden items.
- On Windows 10, check the Hidden items box.
- Locate and copy the Python installation path (typically C:\Users\<yourusername>\AppData\Local\Programs\Python\Python38 or similar):
- In File Explorer, go to This PC > your hard drive > Users > your username > AppData > Local > Programs > Python > the version folder.
- Click the address bar at the top to highlight it, then press Ctrl + C.
- Open System Properties by pressing the Windows key, typing sysdm.cpl, and pressing Enter.
- Click the Advanced tab.
- Click Environment Variables.
- Under User variables, double-click Path.
- Click New.
- Paste the Python path with Ctrl + V.
- Click OK on all open dialogs to save changes.
- Restart Windows to apply the changes. Now you can run scripts with python <filename>.
After successfully running your first script, test it by creating a simple “Hello, World!” Python file to verify everything works. Experiment with command-line arguments by adding them after the filename, like python script.py arg1 arg2, to pass inputs dynamically.
Explore advanced Command Prompt features for Python development, such as using pip to install packages with pip install numpy. Consider learning virtual environments with venv to manage project dependencies separately and avoid conflicts.




