I am used to autostart with rc.local, after making my program called "test3.py" executable (sudo chmod a+x test3.py). I failed to get it autostarted, means as the first program which the Raspi-stretch has to run. Can anybody tell me how to do it right? Attention please: I am a beginner (though 76 years old). Thanks in anticipation! Klaus

  • Have you included the full path to test3.py? Is this file stored in /home/pi - if so it should be /home/pi/test3.py – CoderMike Jan 8 '19 at 23:21
  • Just for the record, Linux kernel always runs "init" as the very first program, and there's no way around that. You should instead specify when your script has to run compared to other system events: e.g. before login, before network is up, before GUI startup, etc. – Dmitry Grigoryev Jan 14 '19 at 8:18
  • Also, explain what " I failed to get it autostarted" means. Is there an error message? Does your script not run at all, or does it stop half way through? – Dmitry Grigoryev Jan 14 '19 at 8:20
  • Dear Dmitry, 1.) the program should start just before GUI. 2.) the program did not start at all. No error message appeared. Spaciba! Klaus – Klaus Jan 14 '19 at 11:07

I don't know what you mean with

I failed to get it autostarted, means as the first program which the Raspi-stretch has to run.

I don't believe that you really want it but will assume it so you will see the implications.

/etc/rc.local is not the best place to start programs on bootup. With old style SysV init system rc.local was meant to start programs as last program after startup. But even that is not guaranteed because with Raspbian Stretch (and Jessie) SysV is replaced by systemd and only emulated by systemd. You have to note that using /etc/rc.local has limitations due to Compatibility with SysV. Following the recommendation of the developers from systemd you should avoid using it.

To run your test3.py program as first program isn't possible because the first program that runs is /sbin/init and that is needed to start all other programs. You have to decide what other programs from the operating system have to run that your program needs to start. You can look at System bootup process what programs when start. A very early point to start your script is just after sysinit.target.

But very common to start user scripts on bootup is after multi-user.target, provided it has only text output and not using graphics. This ensures that all programs and setups from the operating system are available to run the script. To do it you create a new service with a unit file. A very simple unit file for your script you can create with:

rpi ~$ sudo systemctl --force --full edit test3.service

In the empty editor insert these statements (adopted to your needs), save them and quit the editor:

Description=My Test3 program

ExecStart=/usr/bin/python3 /full/path/to/test3.py


Enable the new service and reboot:

rpi ~$ sudo systemctl enable test3.service
rpi ~$ sudo systemctl reboot
| improve this answer | |
  • Hallo Ingo, ich kriege nach "sudo systemctl enable test4.service die Fehlermeldung :'The unit files have no installation config (WantedBy, RequiredBy ,,,,etc) in the [Install] section and DefaultInstance for template units. This means they are not meant to be enabled using systemctl." Das Programm (Eine LED wird von Raspery GPIO pin 7gespeist) funktioniert nicht. Hast Du eine Idee, warum nichtt? Das Programm läuft perfekt, wenn man das Script mit 'python3 test4' manuell startet und ist mit 'sudo chmod a+x test4" ausführbar gemacht worden. – Klaus Jan 14 '19 at 17:52
  • @Klaus, please note that English is the mandatory language on this part of Stackexchange. I think other languages would be fine in chat but on the main site (questions, answers, and comments) you should stick to English for the benefit of all readers beside Ingo. – Ghanima Mar 8 '19 at 10:40
  • @Klaus Sorry for the late answer to your comment but I have seen it just now. With the information you have given I cannot see what's going wrong. Can you please edit the question (the link under the question) and insert the output of this command: systemctl cat test4.service? – Ingo Mar 8 '19 at 11:01


It would help to troubleshoot your problem if you give us a bit more detail regarding what you have tried to so far.

What line did you add to rc.local?

Can you start the script manually?

If everything works, are you using absolute paths for python in rc.local?

If not, make sure your script starts with #! /usr/bin/python in the first line. Then try to start your script in rc.local with ./test3.py

Just a few suggestions until you can provide more details.

| improve this answer | |
  • Tkanks, dear G.Trawo, I added the line /usr/bin/test3.py – Klaus Jan 10 '19 at 7:16
  • I can start the iprogram manually without any problem. – Klaus Jan 10 '19 at 7:17
  • @Klaus Does this mean you got it working the way you wanted? – G Trawo Jan 10 '19 at 15:04
  • Now my rc.local-file reads as: #!/usr/bin/python /home/pi/test3.py It is executable and can manually be tested. Unfortunately the program does not start automatically when starting the PC. – Klaus Jan 10 '19 at 17:30
  • @Klaus Change the line in the rc.local file to '/usr/bin/python /home/pi/test3.py' (without the #!). The #!/usr/bin/python should be at the beginning of your python file (test3.py). That would enable you to start your file by simply typing './test3.py', since it tells the system which interpreter to use (python in this instance). More information on python shebang here: en.wikipedia.org/wiki/Shebang_(Unix) – G Trawo Jan 10 '19 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.