I'm trying to automatically start a py script which has pyqt5 Gui when I boot my Raspberrypi. I did sudo nano /etc/rc.local and made a log.text to know what's happening and I received:

qt.qpa.screen: QXcbConnection : Could not connect to display

How can I solve it? any Ideas?

  • 1
    Maybe because the desktop hasn’t started yet. Probably better to use the LXDE autostart file – CoderMike Oct 1 '20 at 10:51
  • I will try it, thanks – Izo Oct 1 '20 at 10:56
  • +1 For using a log and posting the error. 99%+ of the people who post here about that have not bothered and often have all tried all kinds that didn't work because they were based on incorrect theories about the problem (which is "could not connect to display"). – goldilocks Oct 1 '20 at 14:42
  • Does the script starts from the command line? If so, what exactly is the command? Please add it to the question, don't use a comment. – Ingo Oct 1 '20 at 20:23

Don't try to start foreground applications from /etc/rc.local.

made a log.text to know what's happening


You are possibly the only person I've seen take this time and confusion saving step here in the context of this very common problem -- we get at least one post a week here about this issue, most of them insisting "my script isn't being run", when of course it is, it just isn't doing what you want.

So fortunately we can skip all that and the error is straightforward, if you understand that the init system (systemd, which runs rc.local), is mostly about starting background services, meaning programs which do not need input from the keyboard or a screen to output to. Which is good, because they don't get one.

qt.qpa.screen: QXcbConnection : Could not connect to display

What that literally is about is not being able to connect to a GUI display to open a window.

If you want a GUI application to start at boot, use the LXDE autostart file, as another user suggested in comments. If you search around you will find many examples and discussions of this (there may be some nuances depending exactly what you want to do).

There is also potential confusion regarding the location of the autostart file. It looks to me from a quick search that for Raspbian/RpiOS buster (the current version), this works:


Not sure if that means it is applied to the pi user or if this is global. If it's the latter it may replace the GUI login. If not you will have to use autologin for that user (pi) to start the program at boot.

  • thanks, I will try it – Izo Oct 1 '20 at 15:03

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.