cron and PYTHONPATHFor obvious reasons Dreamhost won’t let users install arbitrary Python packages into the shared site-packages directory, so I keep them in another directory (~/pylib) and add it to my PYTHONPATH.
I was beating my head against the wall because module imports would fail when scripst were run as cron jobs. It turns out that cron runs them in a limited environment, so my custom environment variables, including PYTHONPATH, don’t get loaded.
There are several fixes, but the easiest is to set the variable from within the crontab file:
PYTHONPATH=/home/sam/pylib
0 0 * * * something.py > something.log
Hooray!
(I wonder if I’ll ever learn to read the manual first…)