I still remember the first time I tried to run a Python script on a new machine years ago.
I typed python into the command prompt, hit enter, and was greeted with a “command not found” error.
It is a frustrating roadblock that almost every developer hits when they are starting.
In this guide, I will show you exactly how to add Python to your system PATH so you can run your code from anywhere.
Why You Need to Add Python to PATH
When you type a command into your terminal, your computer needs to know where the executable file for that command lives.
The PATH variable is essentially a list of folders your computer searches through to find those files.
If Python isn’t on that list, your computer won’t know what to do when you tell it to run a script.
Adding it to the PATH makes your development workflow much smoother and allows you to call Python from any directory.
Method 1: Add Python to PATH During Installation
The easiest way to handle this is right at the beginning.
When you download the installer from Python.org, look closely at the very first screen.
I always make sure to check the box that says “Add Python to PATH” before clicking “Install Now.”
If you missed this step, don’t worry; you don’t need to reinstall everything.
Method 2: Manually Adding Python to PATH on Windows
If Python is already installed but doesn’t work in the command prompt, you can add it manually.
First, you need to find where Python is installed on your computer.
Usually, it is tucked away in your AppData folder, something like: C:\Users\[YourUsername]\AppData\Local\Programs\Python\Python312
Once you have that address, follow these steps:
- Click the Start button and search for “Edit the system environment variables.”
- In the window that pops up, click the Environment Variables button at the bottom right.
- Under System Variables, find the one named Path and click Edit.
- Click New and paste your Python installation path there.
- Click New again and add the
Scriptsfolder (it’s inside your Python folder).
I recommend moving these two entries to the top of the list, so your system finds them first.
Method 3: Add Python to PATH on macOS
On a Mac, the process is a bit different because we use the terminal to update a configuration file.
Most modern Macs use the Zsh shell, so you will need to edit your .zshrc file.
I usually open my terminal and run the following command:
nano ~/.zshrc
Then, I add this line at the very bottom of the file:
export PATH=”/usr/local/bin/python3:$PATH”
After saving the file (Control+O and then Control+X), I run source ~/.zshrc to make the changes take effect immediately.
Verify the Setup with a Real Example
Once you have updated your PATH, you should test it to make sure everything is working.
Instead of a basic “Hello World,” let’s use a practical example like checking the current time in a specific US time zone.
Open your command prompt or terminal and type python. If the interpreter opens, you are good to go.
Now, try running this block of code:
import datetime
import zoneinfo
# Getting the current time in New York
ny_tz = zoneinfo.ZoneInfo("America/New_York")
current_time = datetime.datetime.now(ny_tz)
print(f"The current time in New York City is: {current_time.strftime('%I:%M %p')}")You can see the output in the screenshot below.

If you see the current time in NYC printed on your screen, you have successfully configured your environment.
Troubleshoot Common Issues
If you still see an error, the most common culprit is a typo in the folder path.
Double-check that you included the Scripts folder, as this is where pip lives.
Without the Scripts folder in your PATH, you won’t be able to install any third-party libraries.
Also, remember to close and reopen your command prompt after making changes so it can “see” the new variables.
In this article, I showed you how to add Python to the system PATH on both Windows and macOS.
This is a one-time setup that will save you countless headaches as you build more complex projects.
You may read:
- Get Absolute Value in Python Without Using Abs
- Perform Word Count in a Python Program
- Write a Program to Calculate Simple Interest in Python
- Identifier in Python

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.