0

I want to run a python pyQt script in crontab. Generally I put this in the crontab -e:

@reboot XAUTHORITY=/home/user/.Xauthority DISPLAY=:0 && sleep 10 && /home/user/miniforge3/envs/slowcontrol/bin/python /home/user/myscripts.py

But the error log shows like this

   qt.qpa.xcb: could not connect to display:0
    qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
    This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
    
    Available platform plugins are: eglfs, minimal, minimalegl, offscreen, vnc, webgl, xcb.

I googled several suggestions but it didn't help unfortunately:(

like reinstall the xcblib, change DISPLAY=:0 into export DISPLAY=:0 &&. Also I checked the DISPLAY env by env | grep DISPLAY and it is DISPLAY=:0

I really don't have any clue where was wrong. And I am in Scientific Linux 7 which should be similar to either Red Hat or Centos 7.

And of course that code can be run in terminal without any problem.

I really appreciate if you could give any suggestions.

  • Are you sure about the DISPLAY value *and* that the script is actually started when X is active? – musicamante Sep 14 '22 at 22:16
  • https://stackoverflow.com/questions/71864627/python-program-with-qt-5-designer-not-running-on-boot-with-crontab-e/71864769#71864769 – tink Sep 15 '22 at 00:59
  • @musicamante I ran the env | grep DISPLAY after I logged into. And It is DISPLAY = :0 so I suppose that is correct. But how do I checked whether X is active in crontab? – Ryan Zhang Sep 15 '22 at 16:57
  • @tink Thanks for your reply! But I am afraid that that is not I wanted. I want the crontab task run as soon as the pc reboot rather than the user log in. – Ryan Zhang Sep 15 '22 at 17:19
  • That's not going to fly - there's no DISPLAY until you're logged in. What you're after is a single app in [Kiosk mode](https://www.google.com/search?q=linux+centos+kiosk+mode+after+reboot). Or create a user that gets logged in automatically, and use him in your systemd-unit file. Or even easier - put your program in their autostart directory. – tink Sep 15 '22 at 17:34
  • @tink I didn't know much about the kiosk mode and systemd-unit. But I guess if I create a auto login user and put my program in autostart directory, it should be fine? – Ryan Zhang Sep 15 '22 at 17:44
  • Absolutely. If you have no security concerns, that is. – tink Sep 15 '22 at 18:11
  • @RyanZhang As said above, a UI program can only work as long as X is active (with the correct user, or assuming that the user has sufficient permissions). A simple workaround, assuming that you're going to run the program as your user, is to add a startup script when you are logged on (with X) and create a specific file with the correct `DISPLAY` value (so that it can be accessed dynamically), and delete that file at logout; then, the crontab will run a small script that will check if the file exists, reads the value, and run the actual program as expected. – musicamante Sep 15 '22 at 19:27

0 Answers0