Run a Python Script Daily with Cron
To run a Python script once a day, call the Python interpreter with the absolute path to your script from cron. Use the interpreter inside your virtualenv if the script has dependencies, and log the output so you can see failures.
The crontab line
Run crontab -e and add (6 AM daily):
0 6 * * * /usr/bin/python3 /home/user/scripts/job.py >> /home/user/scripts/job.log 2>&1
Use the venv interpreter for dependencies
If your script imports installed packages, point cron at the virtualenv's python — no need to 'activate':
0 6 * * * /home/user/project/venv/bin/python /home/user/project/job.py >> /home/user/project/job.log 2>&1
Always use absolute paths
Cron has a minimal PATH and starts in the home directory. Use full paths for both the interpreter and the script, and for any files the script opens.
Debug with the log
The >> job.log 2>&1 captures errors. A daily job that 'does nothing' is almost always a missing dependency (wrong interpreter) or a relative path.
FAQ
What cron line runs a Python script every day?
0 6 * * * /usr/bin/python3 /path/job.py runs at 6 AM daily. Change the hour and use absolute paths to the interpreter and script.
How do I run a Python script with its virtualenv from cron?
Call the venv interpreter directly: /path/venv/bin/python /path/job.py. You don't need to activate the environment.
Why does my daily Python cron job do nothing?
Usually the wrong interpreter (missing dependencies) or a relative path. Use the venv's python and absolute paths, and log output with >> job.log 2>&1.