5

I've been trying to get the RPi to boot into a custom python script that constructs a simple GUI using pygame, but nothing I attempt has any success.

What are the steps I need to follow to get this working?

Also, if I run startx python start.py -- I get the following error:

FATAL: Module g2d_23 not found.
xinit: Unable to run program "/usr/bin/xterm": No such file or directory

The reason I need it to work this way is because I'm showing a video feed and some other processing in the window that a user can only view and not really break out of (that's the plan).

ghstcode
  • 177
  • 3
  • 9

1 Answers1

6

Non-GUI script

If I want to start any non GUI script, I prefer putting it in rc.local as by the time rc.local gets executed, everything is up by then (network, mysql and any other services like apache etc).

To do that,

  1. sudo nano /etc/rc.local
  2. Add your command before exit 0 line : like python /path/to/script.py >> /dev/null 2>&1 & where path should be absolute path.

Notes on this method :

  1. All the things in the rc.local would be executed as a root user by default.
  2. All the paths in your program should be absolute. It takes home path as /home/pi.
  3. >> /dev/null 2&>1 discards any output on stdout. For more info, why it is used, refer this.

GUI script

To execute anything that uses GUI, (x11), you will have to add that to LXDE autostart file.

Here is how to add,

  1. sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
  2. You should be able to see 3 lines in raspbian by default.
  3. You can add a line at the end to execute your script. for example , @sudo python /path/to/script.py.

Notes on this method :

  1. autostart method doesn't execute script / program as a root user by default.
  2. You might need to add sudo if your program needs it.
  3. If you want to execute without showing desktop part, comment the first 3 lines by putting # in front of every line and add another line after that @openbox which loads open box instead of LXDE.
dhruvvyas90
  • 2,853
  • 3
  • 19
  • 32
  • 1
    Thanks! This worked. I had to add @sudo python /path/to/script.py to get the actual script working, but your answer pointed me in the right direction. – ghstcode Sep 24 '15 at 14:25
  • @SeanNieuwoudt My bad, it was a typo. Let me correct it. :) – dhruvvyas90 Sep 24 '15 at 14:42
  • would you perhaps know how to fill the background of the black area once booted with a background image? Currently, only the Python created GUI shows in a small portion of the visible window and that's how it should be, but would be great to just have a background visible? – ghstcode Sep 24 '15 at 15:07
  • @SeanNieuwoudt I usually have full screen GUI screens and didn't actually looked into it but it shouldn't be very difficult. Google around. – dhruvvyas90 Sep 24 '15 at 15:19