Running a Python script file in the Command Prompt (CMD) involves a simple and straightforward process. Here's a brief description of how to do it:
Open Command Prompt:
Press Win + R to open the Run dialog.
Type cmd and press Enter to open the Command Prompt.
Navigate to the Script's Directory:
Use the cd command to navigate to the directory where your Python script is located. For example:
cd path\to\script\directory
Run the Python Script:
Once you are in the correct directory, run the Python script using the python command, followed by the script's filename. For example:
python script.py
If you are using Python 3, you may need to use python3 instead:
python3 script.py
Press Enter, and the script will be executed.
Verify Output:
If your script produces any output, it will be displayed in the Command Prompt.
That's it! You have successfully run a Python script from the Command Prompt. Make sure that Python is installed on your system and added to the system's PATH environment variable for these commands to work. Additionally, ensure that your script's filename and path are correct.