run python with bat file but python is not recognized as internal

Опубликовано: 23 Июль 2026
на канале: CodeTube
28
0

Title: Fixing 'python is not recognized as an internal or external command' Error
Introduction:
When you encounter the error message "python is not recognized as an internal or external command" while trying to run a Python script using a .bat (batch) file, it means that your system doesn't recognize the Python executable as a valid command. This tutorial will guide you through the steps to fix this issue and successfully run Python scripts using a .bat file.
Prerequisites:
Step 1: Verify Python Installation
Make sure Python is correctly installed on your system. To check, open a Command Prompt and type:
If Python is installed correctly, this command will display the installed Python version. If it doesn't, you need to install Python or fix your installation.
Step 2: Add Python to the System PATH
The 'python is not recognized' error often occurs when the Python executable is not in your system's PATH. The PATH is a list of directories that the Command Prompt searches when looking for executables.
To add Python to the PATH:
Locate your Python installation directory. The default location is usually 'C:\Usersyour username\AppData\Local\Programs\Python\Pythonversion'.
Copy the path to the 'Scripts' directory within your Python installation directory. For example, 'C:\Usersyour username\AppData\Local\Programs\Python\Pythonversion\Scripts'.
Open the Control Panel.
Search for "Environment Variables" and click on "Edit the system environment variables."
In the System Properties window, click the "Environment Variables" button.
Under the 'System Variables' section, scroll down to find and select 'Path,' then click "Edit."
Click "New" and paste the path to the 'Scripts' directory you copied in step 2.
Click "OK" to close all the windows.
Step 3: Test Python in Command Prompt
Open a new Command Prompt window to make sure Python is recognized:
You should see the Python version displayed without any errors.
Step 4: Create a .bat File
Now that Python is in your PATH, you can create a .bat file to run your Python script. Open a text editor (like Notepad) and create a new file with the following content:
Replace 'path_to_your_python_script.py' with the actual path to your Python script.
Save the file with a .bat extension, such as 'run_my_script.bat'.
Step 5: Run the .bat File
Navigate to the location where you saved your .bat file in the Command Prompt and run it:
Replace 'path_to_bat_file_directory' with the actual directory path.
Conclusion:
By adding Python to