Python has become incredibly popular in the world of coding today. When you install Python, you also get an integrated development environment (IDE) called IDLE. This allows you to write and run your Python programs seamlessly. However, you can also run Python programs using the Command Prompt (CMD), which is the default command-line interpreter on Windows.
To use Python in the command-line, you need to set up the environment variable in Windows. Here's how you can add Python Environment to the Windows path:
Step 1: To set up Python on CMD, first, check if Python is installed on your machine. You can do this by searching for Python in the Windows search bar. If Python appears in the search results, you're all set.
Step 2: Check if Python is already set up
To check if Python is already set up in Command Prompt, open the command prompt and type python. If you see a Python version displayed, it means Python is already set up on your system.
From the screenshot above, it appears that Python is not set up in your Command Prompt. When you type python and nothing happens, it indicates that the python command prompt is not recognized.
Step 3: Open Python IDLE
1. Open the Windows search bar and search for "idle".
2. Right-click on the Python IDLE app.
3. Click on "Open file location" to locate the IDLE executable.
4. If you don't see the option, right-click on the app to find it.
After following the previous steps and clicking on "Open file location," a Windows Explorer window will open, showing the location of the Python IDLE executable file.
Step 4: Locate Python IDLE
1. Right-click on the "IDLE" shortcut.
2. Click on "Open file location" to find the IDLE executable.
After opening the file location of Python IDLE, you can copy the path from the address bar of the Windows Explorer window. This path will be used in the next steps to set up Python in the Command Prompt.
Step 5: In the Windows search bar, type "Environment variables" and select "Edit the system environment variables."
Now, in the Environment Variables window, locate and double-click on the "Path" variable under the "System Variables" section. This will allow you to edit the Path variable.
In the "Edit Environment Variable" window, click on "New," paste the file location you copied earlier, and then click "OK." This will add the Python IDLE path to the system's Path variable, allowing you to run Python commands from the Command Prompt.
Now, close the Environment Variables windows by clicking "OK." Congratulations, you have successfully set up the Command Prompt to run Python commands.
Step 6: Test Python Installation
1. Open Command Prompt.
2. Type `python` and press Enter.
3. You should see the Python version displayed.
4. Now you can run your Python programs in the Command Prompt.
Setting up Python in Command Prompt on Windows is a straightforward process that allows you to run Python programs and scripts directly from the command line. By following these steps, you can ensure that Python is properly installed and configured on your system, enabling you to start coding in Python right away.