gotarchery
gotarchery

Reputation: 1

Why a pyqt5 gui won't run on startup?

I have a pyqt5 running on a raspberry pi that I would like to start when the raspberry pi boots. I have tried putting it in /etc/init.d and crontabs. Both seem to run simple bash scripts, I wrote one that writes to a file for testing. But when I try to run a script that calls my pyqt gui the gui doesn't start. Are there logs to look at to see what failed specifically? I think it has to with the visual element of the operating system not having started so my gui doesn't have anything to be displayed on but I could be completely wrong on that.

Does anyone have any suggestions on other things I can try?

Upvotes: 0

Views: 1226

Answers (1)

RaspiManu
RaspiManu

Reputation: 130

I'm actually struggling with the same problem and couldn't solve it, yet.

What I tried and what you could try is:

Option 1: Edit the profile:

1.1 LXTerminal: sudo nano /etc/profile

1.2 profile: sudo python /your/path/pythonscript.py & (& is optional and for scripts with endless loop)

1.3 profile: Ctrl+O to save and Ctrl+X to leave

1.4 LXTerminal: sudo reboot

Option 2: Create autorun-file:

2.1 LXTerminal: cd /home/pi/.config/autostart

2.2 LXTerminal: sudo nano pythonscript.desktop

2.3 pythonscript.desktop:

[Desktop Entry]
Encoding=UTF-8
Type=Application
Name=pythonscript
Exec=sudo /you/path/pythonscript.py
StartupNotify=false
Terminal=yes
Hidden=false

2.4 Ctrl+O, Ctrl+X, sudo reboot

If you already solved our problem, please tell me how.

Best wishes, RaspiManu

UPDATE:

I solved my problem with Option 2. It is important, that you can't use just any path to your script. The script has to be directly in the /home/pi/ directory, so you would use Exec=/home/pi/pythonscript.py in the autorun-file (.desktop). I also learned, that if your script loads for example an image with PIL, this image has to be somewhere else, maybe on your desktop, because it can't be opened out of the /home/pi/ directory.

The autorun file should look like this:

[Desktop Entry]
Version=1.0
Name=YourName
Comment=Your comment
Exec=/home/pi/pythonscript.py -nograb #-nograb for comboBox on touch Screen
Icon=/usr/share/pixmaps/python.xpm
Path=/home/pi/
Terminal=false
StartupNotify=true
Type=Application
Categories=Utility;Application;

Upvotes: 1

Related Questions