My Pi already logs in automatically (goes to Desktop on startup). I wanted my python program to run automatically when pi boots but I need to use the USB numeric keypad input in my program (that is why I need to run the program through the terminal) and with no monitor connected..

So how do I run terminal on startup, then run my python program sudo python /home/pi/Desktop/final/project.pyautomatically on the terminal?

2 Answers 2


You need to specify which OS you are using. I am assuming you are using Raspbian OS.

To open terminal automatically on start up, edit /home/user/.xinitrc and add the following line

exec gnome-terminal &

To run any program on starting terminal,(again, you need to specify which shell you are using. I am assuming 'bash' shell. you can know your shell by typing "echo $SHELL" in your terminal)

Bash and Its Start up File Execution Algorithm

Execution order

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists.

After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The first 2 files do not exist in my setup, so it runs ~/.profile.

When a login shell exits, bash reads and executes commands from the file ~/.bash_logout, if it exists.

When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist.

This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of /etc/bash.bashrc and ~/.bashrc.

        Files run ...      If ...
        1st: /etc/profile  Interactive login shell
        2nd: ~/.profile
        3rd: ~/.bashrc     Interactive non-login shell

Source for Bash start up execution order : http://savage.net.au/Linux/html/bash.files.html

  • Your question is already answered in separate posts in this forum. I have answered assuming you are new to Raspberry PI/Linux. Please search patiently before posting a question.
    – MVSR
    Feb 12, 2015 at 10:17
  • Yes, I'm using Wheezy. I'm going to try your answer when I get home, will update you later. Sorry about that, I have searched prior to asking but they did not work for me (the rc.local and lxde, or maybe I did them wrong) so I decided to ask to allow me follow up questions.. BTW, I saw an answer: gnome-terminal -e "python /path/filename.py" and I tried it in the terminal, another terminal popped up and my project.py ran. That's what I wanted to happen but I just do not know where to put it to run on boot.. any ideas?
    – shindonism
    Feb 12, 2015 at 10:30
  • Try adding that line to "/etc/rc.local" and make sure you give root privileges
    – MVSR
    Feb 12, 2015 at 10:35
  • can you tell me what to do and type at the 2nd part (bash part)? I'm still new to linux and programming alike.
    – shindonism
    Feb 13, 2015 at 2:23
  • create a file named '.bash_profile' in your home folder and add 'python /path/filename.py' as you mentioned above. Just manually open the terminal and verify your program automatically starts or not.
    – MVSR
    Feb 13, 2015 at 4:35

This is for Raspberry Pi where you run your program in a terminal

  • Create a "desktop" file (called "runthis.desktop", for example) in /home/pi/.config/autostart
  • Copy these lines to the new file ("runthis.desktop"):
[Desktop Entry]


Exec=x-terminal-emulator --working-directory=/home/pi/projects/RootCam -e /home/pi/projects/RootCam/main &

Change "Name" and "Exec" as desired and reboot the Pi. Tell your parents you love them.

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.