树莓派开机启动GUI程序

1、如果是lite版,先安装界面,https://www.raspberrypi.org/forums/viewtopic.php?f=66&t=133691

参考上面界面,多种界面添加方法及比较。

2、将我们的程序拷贝到树莓派,依赖库之类的也添加好。

3、要想启动自己的图形界面,就需要启动X server,这个东西是在你登录树莓派输入用户名和密码之前启动的,所以我们可以在启动树莓派之前和启动X server之后启动自己的程序,/etc/profile 这个文件就是这两个程序的中间,我们直接更改这个配置文件就行了

sudo nano /etc/profile
在文件开头输入你程序的路径prg,再执行你的程序guiprogram,如下:

cd /home/pi/prg
./guiprogram

另一种方法是增加环境变量,程序guiprogram在/home/pi/Downloads/dist/下,直接执行即可

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
if [ "`id -u`" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/home/pi/.local/bin:/home/pi/Downloads/dist"
fi
export PATH
guiprogram
发布于 分类 Linux