How to Autorun/Autostart Your Python Script in the Raspberry Pi OS
HTML-код
- Опубликовано: 11 сен 2024
- In this video I'll show a simple and effective method to autorun or autostart your python script. We will create a .desktop file in the home/pi/.config/autostart folder, with the following minimum lines:
[Desktop Entry]
Exec= python3 /home/pi/Desktop/guiautorun.py
Make sure to change the path in the Exec line to the location for your own python script.
Good luck! If you found this information helpful, please like the video and subscribe to the channel for more valuable content:)
Follow me on Twitter: @BaldGuyDIY
Send me an email: brandon@baldguydiy.com
Phew, I tried like 5 different youtube vids before I found this one that actually works. Thanks!
Glad it could help! Thanks for watching.
FINALLY a working method ! I've tried all the other "easy" ways but none did work as well as this one. From a balding guy to another, thanks man!!
Literally a life saver. Thanks for showing the hidden files thing was going crazy trying to find .config
Omg spent so much time trying to make this work!
You’re a life saver dude
That’s exactly how I felt! Thanks for watching.
Thank you so much for that, I have been trying loads of stuff for ages, and yours finally works.
I’m glad it could help! Thanks for watching.
OHH MY GOD
I was looking for 3 days to an autostart solution.
YOU ARE MY HERO RIGHT NOW!!!
I’m so glad it was helpful:) Thanks for watching!
Thank you so much for this tutorial, I never thought it would be this easy to do.
This made my life so much easier than I thought it would be to get this to work! You the man now dawg!
life saver! spent far to long working on this. worked first time. thank you.
Thank you so so much, so many other videos don't make it clear that their methods don't work for desktop apps! This is exactly what I needed!
Thanks for watching. So glad it worked for you!
It works! So very many other answers in this category did not. Thank you!
Absolute lifesaver 😅 i have tried all those methods in your list. Thanks mate!
Honestly dude. Thank you so much for this. I'm currently working on a project that requires servos to boot up automatically and VLC playlist to start at the same moment. This has been a huge help. Subbed
Glad it was helpful. Good luck on your project!
THANK YOU VERY MUCH! I must have been searching for exactly this answer since forever and three days.
At last, something that really works. After hours of testing different forms, this gets the job done.
Thank you very much for sharing it with us. Greetings from Portugal!
Glad it could help. Thanks for watching, and it’s amazing to think my little channel found someone in Portugal!
I dont think you realize how much this helped me, stopped me from spending another 2 Hours smashing my head into a wall, tysm
Fantastic, spent hours trying to get it to work, and you made it so easy.. just subscribed
Thanks, this is the only tutorial I found working, only thing I had to add was put "sudo" before python3 in Exec line because my application needed that to run.
I know I am late for the party, I'm just glad to show up. After investing hours in trying to make a stupid LED flash at startup, your video solved my problem. How did the world function before online videos?
Thank you BaldGuyDIY, Charles
Perfect! Thanks a lot BaldGuyDIY!!! This is actually the only possible way to make my FEH slideshow to run on startup.
Great job!!
Totally wanted 4 days to find this video. Thanks man. Works with shell scripts also. ❤️
Glad it was helpful! Thanks for watching.
After trying so many tutorials, one which even bricked my pi and I lost all my stuff,fortunately had a backup, this one actually worked. Thank you
So glad it helped! Thanks for watching.
Thank you for going through all the steps!
You are right, this is the only method that work for GUI.
Thanks a lot
Works for me tested with tkinter python file. You are the best.
Glad it was helpful. Thanks for watching!
I thought I was just wasteing time watching this tutorial but this actually worked!!!!! Thankyou for spending your time for making this video😁😁
Thank you for watching! Glad it was not time wasted:)
@@BaldGuyDIY I wish I got this more earlier
@@CreativeBrainsOrganization That’s why I made the video! I thought if it took me several hours to find the answer, maybe I could save a few others some time. Turns out it was a LOT of others:)
@@BaldGuyDIY you are such an awesome guy. Expecting more from your side😁😁
fuck man you saved my one more day from running ... doing rnd whole day tried everything and finally this method work ... thanks man
Worked great - First time. Very simple and easy to follow. GREAT job!
I’ve been looking for this for WEEEEEEEKS
My man you’re awesome! Thanks for sharing your findings!
Thanks for this. This is the only method I got to work properly!
love you man couldnt find gui startup anywhere else
As of 2023, definitely wealth the time.Worked for me 💯👌🏽 and I he said for scripts that need to run on the rasp pi desktop.
It verks! It's verking!! Thanks very much for this, saved me a heap of time :-)
So glad it helped. Thanks for watching!
Thanks for the very helpful video @BalGuyDIY
Those having issues: try ensuring you have no spaces in either the file path or the file itself
Thanks for watching and sharing good advice!
i would give you 100000000000000000000000 likes if i could!! when everything else failed THIS WORKED!!!!!!
Thank you bro because of your vdo my final year project got successfully done 🙏🙏🙏👍🏻
Thank you! Thank you! Thank you! I was on the verge of giving up.
Glad it was helpful. Thanks for watching!
Great Video. Thank you so much for saving me tons of heartache
finally got running my server script thanks man
This is really useful. Thank you very much !
Just like you eluded to at the start of the video. I have been searching high and low for an answer! This worked perfectly. I need a total of 8 .py files to open at once!
Although I’ve hit a few snags. The .py files I’m loading are GUI’s created in QtDesigner .. when I use this method none of the assets load with it. (I have images in a sort of slideshow format that display with a button click) any thoughts on why they don’t load?
@@RichPendlebury I haven’t created anything in QT Designer, only PySimpleGUI. Does it work without the auto run?
Thanks for watching! Glad it could be helpful. It was such a relief when I found it myself.
@@BaldGuyDIY normally I have to run it through the terminal which works properly. When I use your method .. it opens but just doesn’t load the images I need to display
What if you run it in the desktop environment from Thonny? If it runs correctly there, it should run fine from the auto run. The only other thing I can think of if that’s the case is that it might take time for something to be initialized on boot before it would work. In that case, build a little sleep delay into the start of the scripts and it should work fine. And if one script needs to be running before the others, sleep delay would work well. Or use one script to import the others in the order you need them and call them at the right time.
i wonder why it doesnt work for me, it works just fine before, i changed my sdcard and tried to do this again but i doesnt work anymore. when i reboot my raspberry i guess it does run because the relay is on but it doesnt show the window that supposed to be shown when i run the program. do you know what did i do wrong?
Thank you sooo much! I was looking for months, to find a solution like this. And it turns out one more time: The most genius things are simple! (You just have to know "how" ;-)). Vielen Dank!!
Glad it was helpful! Thanks for watching.
Thank you for this great tutorial !!
As you mentioned all the other methods were not perfectly running especially for the graphical desktop OS
When I tried your method it started only one time perfectly at startup but then it did not
So I found that the problem is the path of the python script that it should be at
/home/pi/GUI_SCRIPT.py
not at
/home/pi/Desktop/GUI_SCRIPT.py
and this solved the problem in my case then the script is now autostarting every time I boot up my Raspberry Pi :D
Thanks again for your amazing tutorials :)
Thanks for watching and commenting! It just depends on where you’ve saved your script what the path should be. Mine was saved to the desktop, so that’s why it worked for me. If yours was saved to the Pi folder, that explains the need for the oath to be edited. Thanks for watching!
@@BaldGuyDIY Hey! First of all, thank you so much for this tutorial, it worked for me too. However, I had the same problem as Mohammad. No matter where I put my scrip and how I described the path, it would only work if I dumped my script into the /home/pi folder. Strange. Anyways, thank you once again! :)
@@okrimtech I’m glad it worked, and that’s good feedback. I usually start scripts that are on the desktop so I haven’t played with other folders.
Thank you from Portugal for sharing your script 🍓
Muchas gracias! Entre tanto buscar tu explicación me salvó la vida 😃
Thank you for watching!
Thank you! It works on the new raspios bullseye os, which is a bit different than previous ones.
OMG Thank you. Finally it works!
You just saved me ! This is the only method that worked for me !
I’m glad it worked. Thanks for watching!
I was searching for this video and i looked around 30 videos to find exactly this video from this particular creator :P...
Thanks for watching, glad it was helpful!
@@BaldGuyDIY sure it was
You are my hero today!!!
Glad it was helpful. Thanks for watching!
Thanks my friend. Finally got it worked!
You are an angel sir
You are awesome. Thank you for you video and your time.
Thank you very much, It works!! I have tried other ways to a gui to start on boot up. I made a gui for the ir blaster so I can use it with the Raspberry Pi touch screen.
GREAT!! If you want to run in console, change: Exec=lxterminal -e "python3 /home/pi/Desktop/guiautorun.py" ALSO WORKS!!!!!!!
Thank you
Thanks for watching and for the comment. I’m sure that’s helpful for some people:)
Thanks for the info, adding Terminal=true did not work for me but your method above using lxterminal works perfectly and now I can get my script running in a terminal on startup so I can monitor the script output
Thanks a lot!!!!!!
Mate u are a legend thank u. One more question - if i want this script to run every 20 minutes how would you do this, because i’m presuming the other methods that get suggested will run into the same issue of not working
감사합니다. 당신의 영상 덕분에 제 문제를 해결할 수 있었습니다. 한국에서 :)
Thank you for your video. I can solve my problem in Korea :)
Won't work on non gui versions as .config folder is unavailable
Thank you so much for the video. Can we interrupt the python program while it's being executed, like say in case of an infinite loop?
It works for Raspberry Pi 4
Thank you!
It does! I’ve used it myself now too. Thanks for watching and commenting.
Finally it works, thank you
huh, finally! - thank you, this helped a lot!!!
Hello, it only works to a limited extent. I have a Python Modbus script that listens on port 502. When I start the script automatically like this I get the error message that the port is already in use. I've already tried everything possible. But the error only occurs with the autostart function. maybe an idea? Would be grateful!
That was a lifesaver video...
Glad it was! Thanks for watching.
@@BaldGuyDIY yeah... trying the same thing on a raspberry 4 right now.. but seems nothing is happening..
@@refereeweb5304 Try adding Terminal=True to the .desktop file and see if you get any output in the terminal window that would help diagnose the problem.
thanks bro, my problem solved...
Can you help me my script have no gui only in terminal is it possible to linch the script with the terminal window?
Hi BaldGuyDIY, I found this video after some searching. I got a script to auto start during boot but it self exits after 1 to 2 second. The program works fine when started manually. I did try adding a delay when it begins but I believe that the boot sequence is killing the thread. Now sure why.
What does the script do? What modules need to be imported? Without a lot more detail it’s pretty difficult to know the cause. Likely a runtime error, but without knowing which one it’s hard to know how to proceed.
@@BaldGuyDIY Thanks for your reply. The GUI displays serial data from a com port, however its made to run without an arduino plugged in. Only imports are tkinter and serial. I can see serial data updates for a second or two then exit.
@@DT-gm2zi I use PySimpleGUI, which is based on Tkinter. On some Pi’s I need to add 10-20 seconds of delay to the start of the script before it will load consistently at boot.
@@BaldGuyDIY I may have found the solution. I created a .sh file that calls the .py file. It runs instantly and did not close. The only noteworthy thing is all directories have to be fully path defined. Thanks so much BGDIY. Hope this helps others.
Hey actually mine is object detection based project which uses tensor flow but I tried the same method,it didn't work for me in this method , so what else command should I have to use for tensor flow based object detection python code to help it do auto start
Thank you very very very much .
It worked 100% ...
Awesome! Thanks for watching:)
My code needs to use the values from the pickle file so cd myfolder must be used before it can run. Is there a way to write a script run? please.
can i do the same thing but make it run a game on start up essentially making the pi into a designated game of whatever one chooses?
Thanks Guy , perfect!!!! autorun file is working OK!
Claudio Quiñones Glad it could help. Thanks for watching!
thanks bald guy \o/
Hello! I would like start my application before Desktop. The user should not see the desktop. Which method should I use for it? Thank you for any help!
It works!!! you are a life saver :))
Thanks man. Im gonna use this.
Thank you! your videos are the best .
Thanks for watching and the kind words!
It really worked! Thanks!
it finally works out! thanks a lot! :)
Glad it worked. Thanks for watching!
i love you for this tutorial, thanks!
Thanks for watching!
help please. i use playsound to play music but when i restart my raspberry pi, the program works but plays nothing. if you run the program through thonny, everything works fine. What shall I do?
You could add some sleep time to the beginning of your script in case it isn’t leaving enough time for the sound drivers to be initialized. Or use the script to launch another program that plays music.
@@BaldGuyDIY Good idea. I'll try now
@@BaldGuyDIY Did not help(. Do you have any ideas? I waited a minute before importing all the modules (except time) and running the program. Maybe programs running in this way do not have access to audio output? but I didn't get any mistake
@@Тарас-щ9с another commenter had problems with opencv doing an auto run and needed to call to the module within the auto run script. It’s possible that you have to put something in your script to initialize the audio. I’m sorry I don’t have more to offer on it, but if you search for initializing or configuring the audio within a script that may be helpful.
@@BaldGuyDIY thanks
My script starting automatically after booting but close after 1 minute. In IDLE it works without closing
thanks sir, your video very useful
very very very helpful information. thank you
You’re welcome! Thanks for watching, good luck on your projects.
Thanks, finally problem resolved
Glad it worked! Thanks for watching.
awsome Time saving tutorial
Somehow still can't get it to work, not sure what i am doing wrong :(
Thank you! It worked! But then i was simulation power loss situation with unplug from power and it doesnt austostart in fullscreen. Only when i reboot from menu. Do you know how to fix this?
Amazing thanks so much ....but how can i run multiple file in the same time ?????
Can it run at all times when the power is on?
realy use ful
hi how do you make it fullscreen for different screen sizes
Hi, Thanks for This information Is there any way to exit the Window without pressing Exit button
Thank You!!!
❤️ i was finding for linux 🔥🔥
Thanks for watching, glad it could help.
thank u very much, it worked
Works like a charm 😉
Glad it could help! Thanks for watching.
thank you so much man sooooo much
Thank you so much for this I can finally start my script at sartup.
Nice! Thanks for watching:)