When my RPI3 is booted, I would like it to automatically have the terminal open with my python script already running. Note that it loops endlessly. I want to open the terminal so I check the output my script produces.

I have searched ways that auto-runs python scripts on boots. I have tried putting python /home/pi/Desktop/pythonfile.py $ on /etc/rc.local but it just runs in the background and doesn't open a terminal.

What I also tried to do was use lxterminal. In /etc/rc.local, I put sudo /home/pi/Desktop/bashfile.sh &. Then the contents of bashfile.sh were:


lxterminal --command="/bin/bash -c '/home/pi/Desktop/pythonfile.py; /bin/bash'"

When I try to manually run the bashfile.sh, the lxterminal opens and run the python script. However, when I rebooted, it doesn't open a terminal.

Any suggestions to this? Thanks.

2 Answers 2


Is it sufficient for you redirecting the output of the script to a file? You can tail the file to see the real-time output of the script. If so run the script with python myscript.py >& /var/log/myscript.log. It will write the output(stdin/stderr) on file named /var/log/myscript.log.

I think, currently, starting lxterminal in rc.local will not work because the X server is not ready yet.

Depending on your DM you have a file (often called autostart) and you have to put the lxterminal line in it (if you are using LXDE look at this link https://wiki.lxde.org/en/Autostart)


Add a line to the default Raspbian autostart file /home/pi/.config/lxsession/LXDE-pi/autostart:

@lxterminal -e /home/pi/Desktop/pythonfile.py should start your script assuming you made it executable and it contains a valid shebang.

  • I'm not very familiar with graphical user interfaces but I found at the link @MadPapo posted: "LXSession supports the autostarting of applications at login...". Does it mean it does not start a script as part of the boot up procedure without login to a LXE session?
    – Ingo
    Commented Sep 19, 2018 at 10:58
  • 1
    You have to be logged in for the 'autostart' to work. It makes sense since the profile is linked to the user session. And if the user wants to see it on a terminal he has to be logged in anyway. If output to a file is sufficient I would actually use a systemd service.
    – Dirk
    Commented Sep 19, 2018 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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