I would suggest you add the path to Python3 to your cronjob.
Code:
@reboot /path/to/python3 /home/pi/Desktop/sensor_data.py
As noted in my original post, cronjobs do not have access to profile path environment variable.
You can run the following to get the path to your python3 executable if necessary.
Code:
[user@localhost ~]$ which python3
/usr/bin/python3
An alternative would be to put a shebang line at the start of the Python script:
The shebang must be the very first line in the file, before the imports! That tells the shell which interpreter to load, in order to run the script. That way you wouldn’t need to specify the path to the interpreter in cron.
Without specifying the path in cron and without a shebang, the shell will assume the script is written in its own language.
So if your default shell is bash, it will run in bash, if it’s zsh, it will run in zsh.
So, assuming your default shell is bash:
Because your script is a Python script, running it as a cron job without somehow specifying that the script requires the Python interpreter will result in the shell running the Python script as a bash script. And then it will just crash out because the Python syntax will cause bash to throw syntax errors, or command unknown type error messages.
So from the cron perspective the file will just run and fail. The file writing in your script is done via code in your Python script.
That’s why nothing went out to your log files - because none of the Python code got executed.
Adding a shebang to your script, or doing as
@dcbrown73 has recommended will ensure that the shell runs the script as a Python script and your log files will be written to!