I want to be able to open up terminal (gui) on start up and execute a command inside that terminal. I'm placing this inside my /etc/rc.local

x-terminal-emulator -e python /home/pi/pythonFile.py

However this isn't working.. I must be doing something wrong here.

Any help is appreciated, thank you!

  • 1
    give this a try gnome-terminal -e "python /home/pi/pythonFile.py" you may also want to check that you can run the python script from a terminal manually. You may also want to check out this question askubuntu.com/questions/351582/… Dec 8, 2013 at 4:52

3 Answers 3


This assumes you're running debian and doing this from inside a desktop environment: sudo apt-get install gnome-terminal gnome-panel gnome-desktop-icon-edit --create-new ~/.xdg/autostart/your-script.desktop

In the window that appears, fill all fields and check the "run in terminal" box.

The script will now run in a terminal at login, and you can configure your display manager for auto login at this point if you haven't already done so.


Had the same problem trying to run a python script in the terminal at start up, here is what I did.

SPECS: Raspberry pi 3 running OS: Raspbian, Version: 9 (stretch)

1) Go to /home/pi/.config/autostart (If you cant find .config in /home/pi, Right Click in window and check "Show Hidden").

2) Right click>Create New...>Empty File. Name it, [whatever].desktop

3) Right Click on the new file and open in text editor.

4) Pasted the following and edit it to your liking.

[Desktop Entry]
Name=[name of this file, i.e. step 2]
Exec= lxterminal -e [Application, i.e. python3] [full path to the code you want to run]

5) save and reboot.

*There are other things you can put into your.desktopfile but this works for me.


You need to be able to autostart a terminal with a python script that gets opened within that terminal, which is basically a how do I autostart X, Y, or Z program question. Shouldn't be too difficult.

The reason you placing that command within the /etc/rc.local file is failing is because the commands in etc/rc.local are executed as part of the boot sequence, prior to any logins or starting of the X11 server (GUI desktop). x-terminal-emulator is a GUI application, thus it requires a desktop to work.

The way to fix this is relatively simple. You will need to re-run rpi-config as you will need to turn on auto-boot to desktop. If you don't want to do that, things are going to be a lot more complicated.

Once boot-to-desktop is enabled you will need to create a script called .xinitrc in your home directory. Put whatever command you want auto-executed when the x server starts in this file. Once boot-to-desktop is enabled and the xinitrc script created reboot and the desktop should automatically start up and start your python script in the terminal!

Check here for another question that is basically the same as yours.

Hope this helps!

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.