I need to execute a python program at Ubuntu startup.
The script works either run from visual studio code, or from the terminal with the command:
bash -c "python3 /home/complete_path/script.py"
Nevertheless, if I put the same code using the "startup applications", the code is run but it gives back an error.
In order to understand what's going on, I tried many other methods in order to run the file such as modifying local.rc use service or crontab but the result is always the same.
I tried also to automatically launch the terminal and execute the command at terminal startup but the result is not changed.
Which kind of differences are there in a command run at startup or automatically by a terminal vs
manually inserting them? I cannot figure out what's going on.
The system is a Jetson nano with Ubuntu 18.04 installed.
EDIT 1
running it as a service it seems that it cannot import a python module
-- Automatic restarting of the unit mything.service has been scheduled, as the result for
-- the configured Restart= setting for the unit.
gen 18 15:56:33 aisports-desktop systemd[1]: Stopped mything: do my own thing.
-- Subject: Unit mything.service has finished shutting down
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit mything.service has finished shutting down.
gen 18 15:56:33 aisports-desktop systemd[1]: Started mything: do my own thing.
-- Subject: Unit mything.service has finished start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit mything.service has finished starting up.
--
-- The start-up result is RESULT.
gen 18 15:56:33 aisports-desktop mything.sh[7800]: Traceback (most recent call last):
gen 18 15:56:33 aisports-desktop mything.sh[7800]: File "/home/aisports/Desktop/AISports/RGB_control_camera.py", line 11, in <module>
gen 18 15:56:33 aisports-desktop mything.sh[7800]: import depthai as dai
gen 18 15:56:33 aisports-desktop mything.sh[7800]: ModuleNotFoundError: No module named 'depthai'
gen 18 15:56:33 aisports-desktop systemd[1]: mything.service: Main process exited, code=exited, status=1/FAILURE
gen 18 15:56:33 aisports-desktop systemd[1]: mything.service: Failed with result 'exit-code'.
while I still cannot find the log of crontab, since the command
grep CRON /var/log/syslog
gives back
Binary file /var/log/syslog matches
EDIT 2
I solved the missing module problem adding the path of that module at top of the python script through
import sys
sys.path.append('path_to_module')
now the problem that occurs is the same as in case of startup applications:
gen 18 18:08:31 aisports-desktop systemd[1]: Stopped mything: do my own thing.
-- Subject: Unit mything.service has finished shutting down
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit mything.service has finished shutting down.
gen 18 18:08:31 aisports-desktop systemd[1]: Started mything: do my own thing.
-- Subject: Unit mything.service has finished start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit mything.service has finished starting up.
--
-- The start-up result is RESULT.
gen 18 18:08:32 aisports-desktop mything.sh[7763]: [2022-01-18 18:08:32.050] [warning] VideoEncoder setDefaultProfilePreset: passing 'width'/ 'height' is deprecated. The size is auto-determined from first
gen 18 18:08:34 aisports-desktop mything.sh[7763]: Stack trace (most recent call last):
gen 18 18:08:34 aisports-desktop mything.sh[7763]: #2 Object "/lib/ld-linux-aarch64.so.1", at 0x7fb4f57a33, in
gen 18 18:08:34 aisports-desktop mything.sh[7763]: #1 Object "/usr/local/lib/python3.6/dist-packages/numpy/core/../../numpy.libs/libopenblasp-r0-32ff4d91.3.13.so", at 0x7fa055772b, in gotoblas_init
gen 18 18:08:34 aisports-desktop mything.sh[7763]: #0 Object "/usr/local/lib/python3.6/dist-packages/numpy/core/../../numpy.libs/libopenblasp-r0-32ff4d91.3.13.so", at 0x7fa06d4f54, in gotoblas_dynamic_
gen 18 18:08:34 aisports-desktop mything.sh[7763]: Illegal instruction (Illegal opcode [0x7fa06d4f54])
gen 18 18:08:35 aisports-desktop mything.sh[7763]: /usr/local/bin/mything.sh: line 2: 7779 Illegal instruction (core dumped) python3 /home/aisports/Desktop/AISports/RGB_control_camera.py
gen 18 18:08:35 aisports-desktop systemd[1]: mything.service: Main process exited, code=exited, status=132/n/a
gen 18 18:08:35 aisports-desktop systemd[1]: mything.service: Failed with result 'exit-code'.
EDIT 3 (last)
I finally solved the problem.
in .bashrc file I had added export OPENBLAS_CORETYPE=ARMV8
because of the type of the processor. I though that was sufficient also for the startup commands, instead it was not. Adding that line to the startup script, before calling the python script solved the problem.
Thank you @FelixJN for the support on having the log files, that helped me a lot.