How to Configure Python Environment Variables
After installing Python, there are times when the python or pip commands may not work. One of the main reasons for this is that the Environment Variables have not been configured correctly.
In this lesson, we will learn what Python Environment Variables are, why they are important, and how to configure them on Windows step by step.
What Are Environment Variables?
Environment Variables are special settings used by the operating system. They tell Windows where a program has been installed.
For example, when you type:
pythonin Command Prompt, Windows first searches for the location of the Python program.
If the Python installation location exists in the Environment Variables, Python will start immediately.
Otherwise, you will see an error message similar to:
'python' is not recognized as an internal or external commandTherefore, Windows must know where Python has been installed.
What Is the PATH Environment Variable?
One of the most important Environment Variables is PATH.
The PATH variable works like a list for Windows. It stores the installation paths of many software applications.
Whenever you type a command, Windows checks the PATH list to find the corresponding program and then runs it.
If Python has been added to the PATH, you can use Python commands from any folder on your computer.
Why Should You Add Python to the PATH?
When Python is added to the PATH:
You can run Python commands from any folder.
pip commands will work correctly.
IDEs such as Visual Studio Code can automatically detect Python.
Third-party tools can easily use Python.
The development process becomes much easier.
Adding Python to the PATH During Installation
When you open the Python installer, you will see the following option:
Add Python to PATH
If you select this option, the installer will automatically configure the Environment Variables for you.
Selecting this option is highly recommended.
What If the PATH Was Not Configured?
If you did not select Add Python to PATH during installation, you can configure the PATH manually later.
Follow the steps below.
Step 1 – Find the Python Installation Folder
First, locate the folder where Python has been installed.
It is usually located in a path similar to:
C:\Users\YourUser\AppData\Local\Programs\Python\Python313You will also find the Scripts folder:
C:\Users\YourUser\AppData\Local\Programs\Python\Python313\ScriptsYou will need both of these paths.
Step 2 – Open the Environment Variables Window
In Windows Search, search for:
Environment Variables
Then open:
Edit the system environment variables
Next, click the:
Environment Variables...
button.
Step 3 – Edit the PATH Variable
Under User Variables, select the variable named:
Path
Then click:
Edit
Step 4 – Add the Python Paths
Click New and add the Python installation folder.
Then click New again and add the Scripts folder.
For example:
C:\Users\YourUser\AppData\Local\Programs\Python\Python313C:\Users\YourUser\AppData\Local\Programs\Python\Python313\ScriptsBoth of these paths should be included in the PATH variable.
Step 5 – Save All Changes
Click the OK button and close all the windows.
Then open a new Command Prompt or PowerShell window.
Step 6 – Verify the Configuration
Now run the following commands:
python --versionpip --versionIf both commands return the correct output, the Environment Variables have been configured successfully.
What Problems Can Occur If the PATH Is Not Configured?
If the PATH has not been configured correctly:
The
pythoncommand will not work.The
pipcommand will not work.Visual Studio Code may not detect Python.
You may experience problems when creating Virtual Environments.
You may not be able to run Python projects.
Benefits of Configuring the PATH
After Python has been added to the PATH:
You can use Python from any folder.
Installing packages becomes much easier.
Development tools can automatically detect Python.
Automation scripts run more easily.
Your development workflow becomes faster.
Conclusion
Configuring Python Environment Variables is one of the most important steps after installing Python. In particular, if the PATH Environment Variable has been configured correctly, both the Python and pip commands will work from any folder.
The easiest way to configure the PATH is by selecting Add Python to PATH during the Python installation. However, if you missed that step, you can still manually configure the PATH through the Environment Variables and fully use your Python Development Environment.