简体   繁体   中英

How to start and run a python script during boot

First, I apologize for my bad English and now my problem : at the moment I try that my python script camera.py should autostart after the boot has been finished.

However, I tried using rc.local, .bashrc and init.d but nothing will work. Does someone have a better solution, so my script autostarts.

Here you can see the line that I add in my rc.local. Before this line are only blue comments

sudo python /home/pi/Desktop/camera.py &
exit 0

Here is the .bashrc that I used. I only add on the last line of .bashrc those two lines:

echo Running at boot 
sudo python /home/pi/Desktop/camera.py

You should try setting it as a chron job. Check this out: https://www.ostechnix.com/a-beginners-guide-to-cron-jobs/

This will make it run independent of your user login to a shell. Specifically, look at the @reboot section.

Are you sure that it has been added to the end of the .bashrc ?

1.Make sure you are in the pi folder:

$ cd ~

2.To open up .bashrc for configuration:

$ sudo nano .bashrc

Scroll down to the bottom and add the line: python ~/Desktop/camera.py

Save and exit: Ctrl+X, Y, Enter

then reset your pi

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM