bluePiuser
Posts: 9
Joined: Thu Dec 01, 2016 4:10 pm

auto start RPI 3B/3B+ python 3.6 and opencv 3 code

Sat Dec 01, 2018 9:37 pm

After searching and condensing, I figured out how to autostart on reboot python and opencv programs on raspberry pi raspbian stretch. Although it autostarts, if the programs stops, it won't start without a reboot. I didn't succeed yet in doing this as a service. This works with full stretch install.

Create as pi user an sh file:

Code: Select all

/home/pi/run_program.sh
Change permissions:

Code: Select all

chmod 755 run_program.sh
Edit run_program.sh with something like:

Code: Select all

export DISPLAY=:0.0
cd /home/pi/stuff
py opencv_program.py

Then update autostart file.

Code: Select all

cd /home/pi/.config/lxsession/LXDE-pi
Add this line to the autostart file already there:

Code: Select all

@/home/pi/run_program.sh
This works well. If the power goes out, and my RPIs restart, the programs are running. I can connect to desktop directly or with VNC and see the cv2.imshow windows running.

PhatFil
Posts: 764
Joined: Thu Apr 13, 2017 3:55 pm

Re: auto start RPI 3B/3B+ python 3.6 and opencv 3 code

Sat Dec 01, 2018 11:24 pm

look at systemd https://www.raspberrypi.org/documentati ... systemd.md

It will let you define your programs as services with the capacity to stop and start check status etc.

bluePiuser
Posts: 9
Joined: Thu Dec 01, 2016 4:10 pm

Re: auto start RPI 3B/3B+ python 3.6 and opencv 3 code

Fri Dec 07, 2018 8:42 pm

Hi PhatPhil, I created several services that work with python. However, I could not create one python and opencv as the service failed to start. The service could not find a window display at boot time.

Return to “Python”