On my Debian
server I use crontab
to schedule a python
code. The problem is: when I add a line like this:
6 9 * * * python /path/to/daily_task.py &> $HOME/out.txt
Not too surprisingly the output states that python
command is not found.
Of course I can just add a full path to crontab entry like /opt/python/3.9.2/bin/python
, but I don't like this idea because it looks messy and this issue also persists when I need to, for example, do something like os.system("python task.py")
in daily_task.py
.
I tried adding the line like this to /etc/environment
:
export PATH="$PATH:/opt/python/3.9.2/bin/"
After a reboot I indeed could use just python
in my terminal window, but crontab
's $PATH
still only consists of /usr/bin
.
Where should I put this code to change $PATH
everywhere, including crontab
(without altering the crontab file)?
# You can also override PATH, but by default, newer versions inherit it from the environment #PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
, setting a "#" for your path variable, will comment the PATH line and the PATH will be inherited from the environment.