
To run a Python script every day or every hour in cPanel, the recipe is: create a Python application (just to get the virtual environment with your libraries) and make the cron job call that environment’s Python, with the script’s full path. The commonest mistake is calling the system’s Python, which does not have the libraries you installed.
Step by step
|
|
|
|
|
|
What usually goes wrong
| Symptom | Cause | What to do |
ModuleNotFoundError only in cron |
Cron used the system’s Python. | Use the virtual environment’s Python path. |
| It cannot find a config file | A relative path. | Full paths, or work out the folder from the script itself. |
| The log stays empty or only fills at the end | Output is held in memory and only comes out when the program ends. | Run with python -u or write flush=True in your print calls. |
| Two runs at the same time | The first has not finished when the second starts. | Lengthen the interval, or use a lock file. |
| The application’s variables do not exist in cron | Variables set on the application screen belong to the application, not to cron. | Read the configuration from a file outside public_html. |
| Long, heavy scripts do not belong on a shared plan. There are limits on CPU, memory and processes, and a script that exceeds them is stopped. Split the work into short parts, or use a VPS. See the limits nobody advertises. |
| Write an end line to the log, with the date and the result. A log that finishes is proof the script reached the end and was not cut off halfway. |
|
Want a plan with Python and cron in cPanel? See the hosting plans. See the plans |
|
SEE ALSO Python in cPanel: virtual environments and pip Cron jobs: what they are for and how to create one A cron job that does not run or sends no output: a checklist |
RECOMMENDED PRODUCT Web hosting with cPanel Domain and SSL included, daily backups and the panel you already know. from $6.59/mo (3-year plan, with coupon) See plans |
- 0 Users Found This Useful











