I have created an application through Python that has library dependencies on Qt4, pyqt4, pyqtgraph etc. This application is based on Raspberry Pi, I have developed and finished it on the platform.

I want to configure Raspberry Pi to only run that one single application. When I power the Raspberry Pi, it should not go to desktop but run the application (eventually only use necessary packages,library etc).

I have been looking around on different forums on how people do it, but it's not what I'm exactly looking for. There are also different solutions but it's just a bit confusing, that's why I'm here asking for advice/tips on how to implement that.

So far I've tried sudo /etc/profile and at the end of that file I call python3 /home/pi/test.py where i eexecute my application. But I get X cannot connect Server error and Virtual Keyboard Florence is not really registering the button pressed.

  • Starting an graphical application without using a desktop program isn't really specific to Raspberry Pi. I suggest you better ask at unix.stackexchange.com. You may get better answers.
    – Ingo
    Aug 13, 2019 at 19:28
  • /etc/profile is a "# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))" NOT for running programs.
    – Milliways
    Aug 14, 2019 at 5:45
  • 1
    If you use Raspbian Buster Light that comes without a GUI can you start your application from the command line? Or do you need the X Server?
    – Ingo
    May 10, 2020 at 11:31

3 Answers 3


If you want to skip loading the desktop, I would suggest not using the .xinitrc route, but replace loading the session with your own program.

Create ~/.xsessionrc with one line


Create ~/.Xsession with whatever you want to start. You might want to throw in a few lines to avoid screen blanking and screen savers:

xset s off                  # don't activate screensaver
xset -dpms                  # disable DPMS (Energy Star) features.
xset s noblank              # don't blank the video device
python3 /home/pi/test.py    # now start your script

To use xset, you will have to install x11-xserver-utils first:

sudo apt install x11-xserver-utils

This worked for me on a Pi Zero W with Debian Stretch and a Python TkInter GUI.

Sources: askubuntu, stackexchange

  • It's not working...The application doesn't start and I just continue to desktop.
    – Dot
    Aug 13, 2019 at 18:48
  • what is your debian version? try cat /etc/os-release. is your application running when launched from the commandline?
    – ChrisH
    Aug 21, 2019 at 20:07

If you happen to use LightDM, the correct file to start your GUI apps before the desktop environment starts is /etc/lightdm/Xsession. If you want to configure startup differently for each user, you typically put there a line

[ -f ~/.xprofile ] && . ~/.xprofile

and then configure the startup for a given user by editing their ~/.xprofile.


When you are executing a script from /etc/profile, it is running in a terminal context, not a display context.

To run a script whenever the window manager initializes, edit your ~/.xinitrc, and add your script.

For example nano ~/.xinitrc, and add python3 /home/pi/test.py.

  • Didn't work either. I just get to the desktop..
    – Dot
    Aug 13, 2019 at 19:12

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.