How to run scl enable rh-python36 in Linux crontab


Because scl enable rh-python36 create new virtual environment for Python, within this environment, you can use your installed Python 3.6 but this virtual environment not applied automatically while running in a crontab.

So, in order to use Python 3.6 in Linux crontab, you have to run your python files in activated new virtual environment.

My file:

echo "[$now]Running script now ..."
scl enable rh-python36 "cd /opt/wdir/ && pipenv run python" >> /var/log/logrun.txt
echo "[$now]All done now" 

and my crontab:

* 7 * * * /opt/wdir/ > /var/log/logrun.txt 

Another way is to set scl at the crontab directly:

* 7 * * *  scl enable rh-python36 "cd /opt/wdir/ && pipenv run python" > /var/log/logrun.txt 

More about Linux crontab here.

Happy working!