Raspberry Pi學習筆記(十):開機自動執行Python程式

在 /home/pi/.config 下建一個資料夾,名稱為 autostart,並在該文件夾下創建一個xxx.desktop文件(檔名以.desktop結尾,前面可以自定義)

文件內容如下:

[Desktop Entry]
Name=example
Comment=My Python Program
Exec=python /home/pi/example.py
Icon=/home/pi/example.png
Terminal=false
MultipleArgs=false
Type=Application
Categories=Application;Development;
StartupNotify=true

Name(項目的名稱)、Comment(備註)、Icon(小圖示)
Exec 表示使用的指令
sudo reboot 重開機,就可以看到 example.py 自動執行

Written by

Machine Learning / Deep Learning / Python / Flutter cakeresume.com/yanwei-liu

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store