ERROR Unable to import component "image:" on e-paper display

Hello everyone, first of all let me introduce myself: Christian from France, I am a new user of ESPHome 2024.3.1 (without Home assistant for the moment).
I use a LILYGO T5_V2.3 esp32 with waveshare_epaper.

I managed to display different things: time, temp and humidity from HT3x sensor etc. But no image!?

I use the “image:” component

With this example code :

image:
  - file: mdi:alert-outline
    id: alert
    resize: 80x80

But I run into this error:

ERROR Unable to import component image:
Traceback (most recent call last):
  File "c:\users\christian\appdata\local\programs\python\python39\lib\site-packages\esphome\loader.py", line 169, in _lookup_module
    module = importlib.import_module(f"esphome.components.{domain}")
  File "c:\users\christian\appdata\local\programs\python\python39\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "c:\users\christian\appdata\local\programs\python\python39\lib\site-packages\esphome\components\image\__init__.py", line 10, in <module>
    from magic import Magic
  File "c:\users\christian\appdata\local\programs\python\python39\lib\site-packages\magic\__init__.py", line 209, in <module>
    libmagic = loader.load_lib()
  File "c:\users\christian\appdata\local\programs\python\python39\lib\site-packages\magic\loader.py", line 49, in load_lib
    raise ImportError('failed to find libmagic.  Check your installation')
ImportError: failed to find libmagic.  Check your installation
WARNING GPIO5 is a strapping PIN and should only be used for I/O with care.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
Failed config

image: [source lilygoclock.yaml:37]

  Component not found: image.
  - file: mdi:cat
    id: cat
    resize: 20x20

Sorry for the question, but I’m a beginner. Can you help me resolve this error? It looks like a library is missing! libmagic ?? Someone to test ?

Thank you

Hello! I was running into the same issue on Windows and was able to fix it by installing python-magic-bin.
pip install python-magic-bin

Hope that helps

2 Likes

@lrx thanks for this answer (sorry for late response). i install it and i get this error :

Please install the cairosvg python package to use this feature. (pip install cairosvg)

so i install it but i get another error :

OSError: no library called "cairo-2" was found
no library called "cairo" was found
no library called "libcairo-2" was found

another idea ?

Exactly the same error here, although with a different device (SH1106_128X64) and compiling with ESPHome LXC on Proxmox

Try apt install libcairo2-dev

2 Likes

That’s what I was missing, now it works perfectly, thank you very much.

Thanks for your guidance!

I solved my issue installing both libraries

pip install cairosvg
apt install libcairo2-dev