Ranger - image preview not working

I am using Nixos 22.05. I added (ranger.override { imagePreviewSupport = true; }) to my configuration.nix.

However, when trying to preview an image file in ranger, the error message Failed to execute w3mimgdisplay is displayed and there is no preview of the image file.

w3mimgdisplay is not availabe as a package in Nixos so i installed ueberzug but ranger still complains, that it can’t execute w3mimgdisplay although ueberzug is one of the programs that ranger can use for image preview according to its manpage.

How can i fix this?

I added (ranger.override { imagePreviewSupport = true; })

I think this shouldn’t be necessary, as it already defaults to true.

w3mimgdisplay is not availabe as a package

A simple trick for finding the right package is to use NixOS’s command-not-found helper:

$ command-not-found 'w3mimgdisplay'
The program 'w3mimgdisplay' is not in your PATH. It is provided by several packages.
You can make it available in an ephemeral shell by typing one of the following:
  nix-shell -p w3m
  nix-shell -p w3m-nox

The problem you’re running into isn’t a missing w3mimgdisplay, though; ranger shows a different error message in that situation, and in NixOS ranger has been modified to access w3mimgdisplay through the w3m package, which is installed automatically as a dependency.

the error message Failed to execute w3mimgdisplay is displayed

This happens when ranger is able to send commands to w3mimgdisplay but receives an unexpected response back from it. So maybe w3mimgdisplay is returning an error message that we can’t see. As a first guess, are you using Wayland? It looks like w3mimgdisplay doesn’t support that and ranger just expects it to fail like this out of the box.

i installed ueberzug but ranger still complains

ranger won’t detect Überzug automatically; by default it uses w3m. To use a different method, configure that in your ~/.config/ranger/rc.conf:

set preview_images_method ueberzug

As an alternative to installing Überzug directly, you might prefer to add it just as a dependency of ranger. This is a little ugly, but matches the technique already used for w3mimgdisplay:

ranger.overrideAttrs (r: {
  preConfigure = r.preConfigure + ''
    # Specify path to Überzug
    substituteInPlace ranger/ext/img_display.py \
      --replace "Popen(['ueberzug'" \

    # Use Überzug as the default method
    substituteInPlace ranger/config/rc.conf \
      --replace 'set preview_images_method w3m' \
                'set preview_images_method ueberzug'

Ideally something like that would be built in as an option of the ranger package.

If the problem is Wayland compatibility, though, Überzug still won’t help you. There’s some unresolved discussion around this that you might want to keep an eye on. At a glance it looks like only the terminal-specific methods (e.g. kitty) are available.

1 Like

Thank you for your extensive answer!

I am not using wayland and w3m is already installed as a dependency as you said, but the image preview is still not working out of the box.

Anyway, i solved it by editing rc.conf as described by you. Thank you!