starting python script at startup

468 views Asked by At

I serched and tried different ways to start a python script which starts the camera on a raspberry PI3.

first attempt : through crontab

  1. sudo crontab -e added : @reboot python3 /home/pi/camera.py
  2. script : from picamera import PiCamera from time import sleep camera = PiCamera() camera.framerate = 15 camera.start_preview()

second attempt through crontab :

  1. sudo crontab -e added : @reboot /home/pi/launcher.sh >/home/pi/log/cameralog.log 2>&1
  2. script camera.py stays thesame
  3. launcher.sh : #!/bin/bash clear cd / cd home/pi /usr/bin/python3 /home/pi/camera.py cd /

third attempt :
removed all from crontab and used rc.local sudo nano /etc/rc.local added : /usr/bin/python3 /home/pi/camera.py&

Non of the above ways is starting the script at reboot.

I'm new to raspberry and python. what's wrong?

1

There are 1 answers

0
Witzend On

Type-

sudo nano /etc/profile

at the end of the file add the following line

sudo python2 (or 3) yourfile.py