I have a program I have written which has lots of dependencies including tensorflow and perhaps more importantly tKinter (via pySimpleGui). So yes its a program with heavy computation on the backend and a GUI on the front end. I simply want the program to load on boot which would seem like a trivial task but that’s when I fell into a bottomless pit. I have tried pretty much everything in the forum over two days including:
#1. Try using a desktop file to run the python script:
Create file ~/.config/autostart/craigsstartup.desktop with:
[Desktop Entry]
Encoding=UTF-8
Name=myscript
Comment=myscript
Icon=gnome-info
Exec=python3/home/craig/helloworld.py
Terminal=false
Type=Application
Categories=
X-GNOME-Autostart-enabled=true
X-GNOME-Autostart-Delay=0
Result: Nothing happened...
(tried many variations of this)
#2 Try putting python script
in “STARTUP APPLICATIONS” APP ON DESKTOP`
PLACED INSIDE COMMAND BOX:
python3 /home/craig/helloworld.py (just to see it work)
RESULT
Nothing Happened
#3.Try using a systemD service:
Create a shell script named
/usr/local/bin/craigstart.sh`
Place in it:`
#! /bin/bas
/usrbin/python3 /home/craig/helloworld.py`
sudo chmod +x craigstart.sh`
run with: ./craigstart.sh
RESULT:
Running the shell script by itself produces
“hello world” as expected… and it also works
with my complex program.
Now I created a file called “/etc/systemd/system/craigstart.service”
[Unit]
Description=mythingcd
After=graphical.target
[Service]
Type=simple
Environment=DISPLAY=:0
ExecStart=/usr/local/bin/craigstart.sh
[Install]
WantedBy=graphical.target
Then ran these commands in a shell:
$ sudo systemctl enable craigstart.service
$ sudo systemctl start craigstart.service
$ journalctl -u craigstart.service –since “5 mins ago”
Also tried adding
Environment=“DISPLAY=:0”
“XAUTHORITY=${XDG_RUNTIME_DIR}/gdm/Xauthority”
And tried:
Environment=“DISPLAY=:0”`
Environment=“XAUTHORITY=/home/craig/.Xauthority”
and…`
Environment=“DISPLAY=:0”
“XAUTHORITY=${XDG_RUNTIME_DIR}/gdm/Xauthority”`
Result: No banana sir
- Added a fix to the beginning of my python code to
address the error I was getting with the systemD process - specifically
(Error:_tkinter.TclError: coundnt connect to dsplay “:0”
The code fix was as follows in my python code:`
import matplotlib
matplotlib.use(‘Agg’)
Result: No cigar
- At this point I could kind-of see what was going on. Namely I am trying to use graphics processing before the X session had begun and none of the startup schemes seem to work that late in the boot process. So I next tried this command:
xhost+SI:localuser:root`
This logged the root in as an xhost user and as a result I was able to get
the systemD service working using the systemctl commands in
the terminal. So I decided to put this xhost
statement in the shell file for the systemD service and it would not work – due I believe to no user having logged in yet to the X session on bootup so it was a chicken and egg situation... I still have hopes for the systemD approach but I just cant get the service to start late enough for it to work…
There are suggestions in the forum of using the STARTX script but I couldn’t find any good examples of that working for a situation like mine, I played with it for a bit but when I crashed my system I said enough of that….`
RESULT:
No Success
So I have this big beautiful python program with GUI functionality which runs a complex robot that I have been working on for 11 months and I just cant figure out how to boot the program on startup.
It is a depressing situation. Any suggestions would be helpful. I know from the posts I am not the only one in this boat, others have tried to boot a GUI based program but I didnt see anybody succeeding. Any help would be greatly appreciated. Craig