I have a Python script running on a Raspberry Pi Zero W that calls the image program feh in order to loop through some directories and display the enclosed images. The script is supposed to run on startup - think of it as a sort of headless image-display program. I'm running not the latest version of Stretch, but the one released in Oct. 2018.

In order to get everything to run on startup, I've edited the ~/.config/lxsessions/LXDE-pi/autostart file. I'm using an external projector, so in order to display the images correctly, my autostart file looks like this:

/usr/bin/python /home/pi/myscript.py

Then my Python script basically looks like

import os
import psutil
import time
while True:
    os.system('feh --hide-pointer -x -q -B black -g 1280x720 ' + img_dir + ' &')
    for process in psutil.process_iter():
        if 'feh' in process.cmdline():

and I loop through different image directories. I know that using os to make system calls is deprecated, but it's the only way I could get this particular call to work.

So here's the problem: if I reboot the Pi from the command line, everything works swimmingly. The Pi boots up, the Python starts running, and the images are displayed correctly, looping forever. If I do a cold start, however, only the Python script runs - no images are displayed. I know this is happening because I can log in remotely and see that the Python program is indeed running, but feh is not, while it is running after a reboot.

The only other thing I can think might be relevant is that I had issues with the Pi's projector/display going to sleep (i.e., going dark after no external input after a minute or so), so I edited the /etc/lightdm/lightdm.conf file and added

xserver-command=X -s 0 -dpms

What's going on with feh? Is there a log file somewhere I can look at to see if it's throwing any errors? Is my no-sleep call screwing things up? Why does the Python run without fail, but not feh? Any input here is welcome!

1 Answer 1


For anyone that comes across this, the answer is to sleep for a while. In the autostart file, adding the line

sleep 5




/usr/bin/python /home/pi/myscript.py

apparently allows all necessary display drivers to load before feh and the Python script start. Problem solved, as long as you don't mind waiting a few extra seconds.

  • Please accept your own answer with a click on the tick on its left side. This will finish the question and it will not pop up every year again.
    – Ingo
    Nov 5, 2019 at 12:05

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.