Ever wanted your Python scripts to run automatically — every hour, every morning, or after reboot? You don’t need to keep your terminal open or build a full app for that. Windows Task Scheduler can handle it for you — and you can even run your scripts silently in the background.
In this post, we’ll cover:
- How to schedule a
.py
file to run automatically - How to run it without opening a Command Prompt window
- What’s the difference between
python.exe
andpythonw.exe
Step 1: Yes, You Can Schedule Python Scripts!
Windows Task Scheduler is a built-in tool that lets you automate Python scripts to run:
- At a specific time (e.g. 7:00 AM)
- On a recurring basis (e.g. every 30 minutes)
- At startup or login
- After an event (e.g. system idle)
This means you can automate scripts for:
- Sending emails
- Scraping websites
- Running trading bots
- Updating spreadsheets
- Cleaning up files
- Pulling API data
Step 2: How to Set It Up in Task Scheduler
- Open Task Scheduler from the Start Menu.
- Click “Create Task…” (not “Basic Task”).
- Under the General tab:
- Give it a name (e.g. “Run My Script”)
- Select “Run whether user is logged on or not” if needed
- Go to the Triggers tab and click New…
- Choose how often it runs (daily, hourly, at startup, etc.)
- Go to the Actions tab and click New…
Three Key Fields in the Actions Tab
Here’s how to fill out the three main fields:
Field | What to Enter |
---|---|
Program/script | Full path to Python interpreter (python.exe or pythonw.exe ) |
Add arguments | The full path to your .py or .pyw script in quotes |
Start in | The folder path (directory) where your script is located (no trailing slash) |
Example:
- Program/script:
C:\Users\YourName\AppData\Local\Programs\Python\Python311\pythonw.exe
- Add arguments:
my_task.py
- Start in:
C:\Scripts
\
By Default, the Script Pops Up a Window
If you use python.exe
, Task Scheduler will open a black Command Prompt window every time your script runs. That’s fine for testing, but distracting for background tasks.
Step 3: Run Silently with pythonw.exe
To suppress the command window, just switch to pythonw.exe
in the Program/script field.
Executable | Description | Shows Terminal? |
---|---|---|
python.exe | Default Python interpreter (CLI) | ✅ Yes |
pythonw.exe | Windows GUI-friendly version (silent) | ❌ No |
You can continue using .py
files — there’s no need to rename them to .pyw
.
Recap
To schedule Python scripts and run them silently:
- Use Windows Task Scheduler
- Point to your Python interpreter and script path
- Use
pythonw.exe
for background execution - Set the “Start in” field to your script folder
That’s it — no pop-ups, no interruptions.
Pro Tip:
This method works great for background jobs, bots, scrapers, automation scripts, and more — all without installing extra software.