Why is my script running if run with cli but not with crontab?

This python script makes use of an environment variable to work, I wonder if that is the reason.

Yes, when executed via /bin/sh with a command (as anacron is doing by default), the shell is not a login shell, so ~/.profile doesn't get sourced.

Although I have tried to include . $HOME/.profile; in the crontab right before the command above; without success.

This worked for me. I added export abc=123 to my ~/.profile and added the following to /etc/crontab:

*  *    * * *   username    . $HOME/.profile && true && echo $abc >> $HOME/crontest

The resulting ~/crontest correctly displayed a 123 for every minute passed.

Another alternative would be to force the sh to run as a login shell (-l), and pass in your script via -c:

*  *    * * *   username    sh -lc 'true && echo $abc >> $HOME/crontest'