If you've ever installed Python on a Windows machine but encountered issues running Python commands in the terminal, you might be facing a missing Path variable entry. Recently, I solved this issue by manually adding Python to the Windows environment variables. Here’s how you can do it too.
The Problem
After installing Python, you might open the Command Prompt and type:
python --version
and receive an error stating that Python is not recognized as an internal or external command. This happens when Python’s installation path isn’t added to the system’s environment variables.
The Solution
To fix this, follow these steps:
Step 1: Locate the Python Installation Directory
Open the Windows search bar and type Python.
Click on Open file location to navigate to the installed Python folder.
Inside this directory, locate the Scripts folder. The path should look something like this:
C:\Users\YourUsername\AppData\Local\Programs\Python\PythonXX\Scripts
(where
PythonXX
represents your installed version of Python, such asPython39
for Python 3.9).
Step 2: Add Python to the Environment Variables
Open the Windows Search and type Environment Variables, then select Edit the system environment variables.
In the System Properties window, click on the Environment Variables button.
Under System Variables, find and select Path, then click Edit.
Click New and add the full path of the Scripts folder you found earlier.
Also, add the main Python directory path (e.g.,
C:\Users\YourUsername\AppData\Local\Programs\Python\PythonXX
).Click OK to save your changes.
Step 3: Verify the Installation
To confirm that Python is correctly added to the Path:
Open Command Prompt and type:
python --version
or
python
If Python starts without an error, the setup is complete!
Conclusion
Adding Python to the Windows Path variable manually ensures that you can run Python commands seamlessly from any terminal window. If you ever run into the same issue, simply locate the Python directory and update the environment variables as outlined above. Happy coding!
Comments
Post a Comment