Helped me; might help others. If it works in the command tab and not as a cron job, it might be trying to run before dependencies are available. You can give the pi time to first fully boot by delaying the script to run 30 seconds later as follows: @reboot sleep30; python3 home/pi/Desktop/…etc
The solution is to run a terminal with the command to run code steps :- . Make sure script is executible chmod +x /home/pi/your program.py .Open crontab. -e crontab -e . Entre command @reboot lxterminal -e /usr/bin/python3 /home/pi/your_program.py And use (&) in if code is not running with above command thank U .
I had same issue. You have to put some prefix before the python script. For me my VE was named venv1 so my script looked like this: venv1/bin/python3 /home/pi/Documents/player.py Hope that helps
Excellent! Short and to the point. I did "crontab -e" without the sudo, because the system seems to boot into my user name. Not sure about this. Thanks again.
Those who are wondering how to undo this : Open crontab: crontab -e (or sudo crontab -e if you used sudo initially) Find the entry: Look for the line you added earlier, which starts with @reboot. Delete the entry: Remove the entire line by pressing dd (or use the delete key). Save and exit: Save the changes and exit the editor.
If you are running the script with root priveleges you dont, but if you dont those commands will just not go through because the permission gets denied.
with this, does the pi also not need to be able to log in automatically with the username and password? How can it run the code without logging in first?
Hey is it possible to call to run multiple files at the same time on startup and/or would it be as simple as another line imitating what is shown for the second python file to run?
for those where crontab didnt do anything, in nano editor, try pressing ctrl+T and then execute the python code and if you have any error, once the code runs without any error in nano editor, delete the generated lines and sudo shutdown -h now, switchoff and then on Peace Out!
Hey. How do I get it to boot up where I left off at? I’m using it to monitor my vehicles gauges and have made adjustments but when I power down ot doesn’t start where I left off and have to make those adjustments again.
I have a python script that involves neopixels. I have to go to terminal and type sudo thorny to open thorny and write the script. The script is saved in the root disk or memory. How can I get a program like that to start from start up?
I activated the code and it worked, my servo would spin but the whole program only ran for a few seconds before stopping, how do i make it run continuosly until the power is cut?
i have a question if you need to update your bash file , how can you do that ? i have to make changes to it but when i update the image is keeping the original file i set to for automation..
In my case I created a server with python, and my sever uses a CSV file for checking some data. Now how I can set the working directory of my server so that any data file my server needed can easily executed !
This is good, its an easy way of doing it.! however, making daemons is the way to go when you need to ensure a program that crashes can re-open automatically.
when I try to run the python code in one line I get an error saying it can't see the the other file names in the folder like tiffs even tho they are in the folder if I use this line python3 DEV/poster/poster49.py it errors but in terminal if I cd DEV/poster then run python3 poster49.py it runs fine. Don't understand why I can't run in one line
Hey thanks what if I want to run two scripts for example a python and a pure data one? I tried putting both in @reboot on crontab but it did not work for the second.
You have to separate the commands with semi-colons. If that doesn't work then there's something wrong with your other command. Try running the command in your terminal and see if it works before trying it in crontab
Hi thank you for the video, I want to run an executable, in this case its Universal Gcode Sender (an application for CNC machines) but it wont boot on start up, there was no error messages displayed, do you know what could be the problem?
can i burn this script along with os image file to execute script post installation? My objective is to install few software and configure few settings in raspberry pi post os installation
hey is there a way for the Pi to run a sudo command upon boot? I'm running VirtualHere USB over IP and i want my Pi to run a Terminal sudo command every time it boots.
Does this not work for pygame? I keep getting errors saying that directories included in the code don't exist when I try to run it from the terminal. If I run it from and IDE it works fine. Any suggestions would be much appreciated. I'm a total noob.
@@SamWestbyTech thank you sam.....now i have completed running a basic program when booting up ( like a led blink, etc.). my main program is running successfully in the python terminal but when writing it in crontab it's not working how to diagnose the problem...
Yes this is possible. I believe you just have to edit the crontab file to be the command to activate your virtual environment, then a semicolon “;”, then the command to run your script
if I type: "python3 main.py" it runs But if I type the entire path: "python3 /home/pi/main.py" it won't run.. and I get: "can't open file: [Errno 2] No such file or directory" Anyone had my same problem? How can I fix this? Thanks
Open your terminal and try typing "ls /home". This lists the files in the "home" directory. Do you see "pi" in the output? Next type "ls /home/pi". What files do you see? Do you see "main.py"? If not, then main.py is in a different place
You should have made the video a little more complex like adding two or more scripts to run at startup. Because that's what im trying to figure out how to do right nw
bro. trying to get a wifi tool to run on startup on pi zero with re4son kernel for a week. followed every long ass convoluted tutorial seven times and youtube hid this video until i was digging so deep most of the results werent even relevant. algorithm sucks
Hello, great and easy advice. Question. How do you go back to normal mode? What if you want to go back to R-pi to modify script or go back to the use of monitor and keyboard?
@@SamWestbyTech This video is awesome. Helped me a lot to get my application working easy. I m new R pi user and I did not know if after this set up as shown on your video I could have my keyboard and mouse connected or not to my r-pi. Many thanks again my application works as desired.
I've never had a tutorial from a gfloating head before. Are you preparing for a Futurama future? 😅 Sorry, jk, but the vid would look better with a wider shot.
with this, does the pi also not need to be able to log in automatically with the username and password? How can it run the code without logging in first?
thank you! so many other people were saying to do this in the most convoluted way possible.
Helped me; might help others. If it works in the command tab and not as a cron job, it might be trying to run before dependencies are available. You can give the pi time to first fully boot by delaying the script to run 30 seconds later as follows:
@reboot sleep30; python3 home/pi/Desktop/…etc
Tried sleep60, sleep 60...Still not work. Don't know why
@@mingjianli8718 I have same problem..
Tried it, but still isnt working
does not work
The solution is to run a terminal with the command to run code steps :-
. Make sure script is executible
chmod +x /home/pi/your program.py
.Open crontab. -e
crontab -e
. Entre command
@reboot lxterminal -e /usr/bin/python3 /home/pi/your_program.py
And use (&) in if code is not running with above command thank U .
I LOVE YOU JUST FIXED A PROBLEM I HAVE BEEN HAVING FOR 2 YEARS
Absolute life saver, why it no other tutorial this simple??
thank you for keeping it straight to the point and not having a 20 step program :D
The command is working properly so simple and straightforward .
Life saver 🎉🎉🎉 working on a installation was the last part i needed
what if i need to turn on a virtual environment before running the script? do i add the 'source env/bin/activate' command in the cron file?
Hi! How do I do this if my python script is on a virtual environment?
hey did you got an update about that i had the same problem thanks
@@rafinursandi5828 Any updates?
I had same issue. You have to put some prefix before the python script. For me my VE was named venv1 so my script looked like this:
venv1/bin/python3 /home/pi/Documents/player.py
Hope that helps
@@ThatMusicBlogomg. After a month of searching for this answer i find it in a youtube comment. Thank you so much
Excellent! Short and to the point. I did "crontab -e" without the sudo, because the system seems to boot into my user name. Not sure about this.
Thanks again.
you saved me hard man. THANK. YOU take care
Those who are wondering how to undo this :
Open crontab: crontab -e (or sudo crontab -e if you used sudo initially)
Find the entry: Look for the line you added earlier, which starts with @reboot.
Delete the entry: Remove the entire line by pressing dd (or use the delete key).
Save and exit: Save the changes and exit the editor.
danke. das wollte ich so schnell wie möglich nochmal wissen.
thank you so much for your input, it's great
terminal works but doesnt run on start up
Thank you so much for this tutorial, but I had one question
Do I need to do anything differently if I am running a script that needs SUDO privileges?
If you are running the script with root priveleges you dont, but if you dont those commands will just not go through because the permission gets denied.
Hi... to stop and back to normal, is it just use a ssh and edit this line on crontab?
Thank you! Perfect!
with this, does the pi also not need to be able to log in automatically with the username and password? How can it run the code without logging in first?
U can enable auto login in raspberrypi configuration
Awesome! Now how do I get it to not run on start up?
Hey is it possible to call to run multiple files at the same time on startup and/or would it be as simple as another line imitating what is shown for the second python file to run?
IDK what happen, my project is running but not reproduce the mp3 in this way. Can you help me, please?
for those where crontab didnt do anything, in nano editor, try pressing ctrl+T and then execute the python code and if you have any error, once the code runs without any error in nano editor, delete the generated lines and sudo shutdown -h now, switchoff and then on
Peace Out!
Hey. How do I get it to boot up where I left off at? I’m using it to monitor my vehicles gauges and have made adjustments but when I power down ot doesn’t start where I left off and have to make those adjustments again.
thx you so much, works perfectly
I have a python script that involves neopixels. I have to go to terminal and type sudo thorny to open thorny and write the script. The script is saved in the root disk or memory. How can I get a program like that to start from start up?
I activated the code and it worked, my servo would spin but the whole program only ran for a few seconds before stopping, how do i make it run continuosly until the power is cut?
Did you solved the issue?
If yes please guide, facing the same problem
Do I need to use ,
While True:
?
thanks Sam!
Wait wait wait... I only you know as a bike celebrity!
Quick and easy. Gratz
You're the best!
what if you want to run multiple bash scripts one after the other because I have to run startx followed by two bash scripts
'
How about when we don't want the code to run at startup in the future? Do we just delete the crontab command?
I need that every time the Raspberry Pi starts, it opens a photo in a specific folder and puts the photo in slideshow mode. How can I do this?
well made and helpful
Your content is very helpful , thank you .
it workeddd thanks!
i have a question if you need to update your bash file , how can you do that ? i have to make changes to it but when i update the image is keeping the original file i set to for automation..
In my case I created a server with python, and my sever uses a CSV file for checking some data. Now how I can set the working directory of my server so that any data file my server needed can easily executed !
This is good, its an easy way of doing it.! however, making daemons is the way to go when you need to ensure a program that crashes can re-open automatically.
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.
when I try to run the python code in one line I get an error saying it can't see the the other file names in the folder like tiffs even tho they are in the folder if I use this line python3 DEV/poster/poster49.py it errors but in terminal if I cd DEV/poster then run python3 poster49.py it runs fine. Don't understand why I can't run in one line
Hey thanks what if I want to run two scripts for example a python and a pure data one? I tried putting both in @reboot on crontab but it did not work for the second.
You have to separate the commands with semi-colons. If that doesn't work then there's something wrong with your other command. Try running the command in your terminal and see if it works before trying it in crontab
hi can i run grc files in above mentioned method? please reply...
Hi thank you for the video, I want to run an executable, in this case its Universal Gcode Sender (an application for CNC machines) but it wont boot on start up, there was no error messages displayed, do you know what could be the problem?
i have the same issue
Does anyone know how I can make my pi wait until it is connected to the internet before running the script?
Short
Easy
Helpful
How can I change the editor again, I chose wrong when I asked myself. pleasee
can i burn this script along with os image file to execute script post installation? My objective is to install few software and configure few settings in raspberry pi post os installation
hey is there a way for the Pi to run a sudo command upon boot?
I'm running VirtualHere USB over IP and i want my Pi to run a Terminal sudo command every time it boots.
I'm having the same issue, I just found out it does not run commands with root :(
Cool luv it
Thank you.
Can I just add the bash command directly in the crontab file?
but if my script uses or calls other files/folders?
I need to run a command prompt .sh at startup and leave it open, I tried this and no sign of the command prompt
Does this not work for pygame? I keep getting errors saying that directories included in the code don't exist when I try to run it from the terminal. If I run it from and IDE it works fine. Any suggestions would be much appreciated. I'm a total noob.
Make sure the required files(example: mp3 files) are in the same folder as your code
Thanks Man Appericiate the content
Is this working on Jetson nano?
Thx it helped me
super...I have one doubt.....if i want to run a python file in diffierent environment (not from the base environment ex: PyTorch) how to do that?
I believe you just need to add the command to activate your environment, then a semi-colon, then the command to run your Python file
@@SamWestbyTech thank you sam.....now i have completed running a basic program when booting up ( like a led blink, etc.). my main program is running successfully in the python terminal but when writing it in crontab it's not working how to diagnose the problem...
Thank u so much
Hello, how do you stop the program after running it?
Try using the command sudo crontab -r (I'd recommend checking your list of crontab commands first by using sudo crontab -l)
How to print log file ?
Hi mate, I have a face detection code on Raspberry Pi, and it works on pycharm. How can I work it like that?
Hey can u give your code i really need it if u can share it with me
life saverr
Cowabunga dude!
It's not working in my case. Can you please help me
👏👏
Hi, can i ask how to run a script on startup in a virtual environment?
Yes this is possible. I believe you just have to edit the crontab file to be the command to activate your virtual environment, then a semicolon “;”, then the command to run your script
if I type:
"python3 main.py" it runs
But if I type the entire path:
"python3 /home/pi/main.py" it won't run.. and I get:
"can't open file: [Errno 2] No such file or directory"
Anyone had my same problem?
How can I fix this?
Thanks
Open your terminal and try typing "ls /home". This lists the files in the "home" directory. Do you see "pi" in the output? Next type "ls /home/pi". What files do you see? Do you see "main.py"? If not, then main.py is in a different place
how about screensaver video bro?
After this how can we return to the desktop
Same question.
use putty
sir can we auto run the file which contain text and python script
yes you can!
Hi, I have watched and followed the instruction shown in the video. However, it did notwork. I don't know what the problem is.
When you run the commands in your terminal do they work? That's how you can troubleshoot before trying them in crontab
@Sam Westby Tech the terminal did the exact thing as shown on the video. However, it just don't run the code as expected to when I restart the pi
@@bobyau8755 Hi Bob, I am getting the same error, could you solve it ?
@@tusharalase7472 not yet, I'm in uni, need to be back at home to play with my robot
cant get it to work im afraid.. followed exact
can you make a video on that
How do you run multiple scripts?
Separate them with a semi-colon
sadly is only working in the terminal, but not on reboot
You should have made the video a little more complex like adding two or more scripts to run at startup. Because that's what im trying to figure out how to do right nw
hi i want How to Run a scratch3 Script on Startup for Raspberry Pi 4
That’s helpful. I have a script for my Sense hat. Do I have to type python3 in as well?
Thank you so much. You saved my live.
What you type in your terminal is what you use. If you type python3 when you normally run the script, then include python3
@@SamWestbyTech Thank you.
for me its not working
great job friend, but i want to notice noobs like me that for me worked only without 'sudo'
bro. trying to get a wifi tool to run on startup on pi zero with re4son kernel for a week. followed every long ass convoluted tutorial seven times and youtube hid this video until i was digging so deep most of the results werent even relevant. algorithm sucks
Not working for me
Hello, great and easy advice. Question. How do you go back to normal mode? What if you want to go back to R-pi to modify script or go back to the use of monitor and keyboard?
Thanks, Sam. What do you mean by normal mode? If you mean how to exit the Nano text editor, you can press CTRL+S to save then CTRL+X to exit
@@SamWestbyTech This video is awesome. Helped me a lot to get my application working easy. I m new R pi user and I did not know if after this set up as shown on your video I could have my keyboard and mouse connected or not to my r-pi. Many thanks again my application works as desired.
I've never had a tutorial from a gfloating head before. Are you preparing for a Futurama future? 😅
Sorry, jk, but the vid would look better with a wider shot.
Didn't work
Didn’t work for me
dont know why but this didnt work for me
dont work at all
What did you put in the crontab? And wdym it doesn't work?
with this, does the pi also not need to be able to log in automatically with the username and password? How can it run the code without logging in first?
After setting up the pi, you shouldn’t need to log in again ever. Unless you log out before shutting down
Tks you so much
How do you disable it?