Using Pillow with AppDaemon4

Hello.
I am trying to use Pillow for processing images in AppDaemon. I’ve been at it for a while now. AppDaemon says Pillow is installed but I cant import it with a script.

I am using HASIO and the Supervisor install of AppDaemon4 (version v0.7.0). I’ve had that running for a while and have 4 or 5 other scripts that run just fine.

I now added Pillow to the config tab in supervisor

Here is my AppDaemon start up log, it now shows Pillow installing successfully. But I note that I get this installing message about downloading and installing Pillow every time I restart AppDaemon. So I wonder if its really getting registered in the module list?

Help is greatly appreciated.

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 00-banner.sh: executing... 
-----------------------------------------------------------
 Add-on: AppDaemon 4
 Python Apps and Dashboard using AppDaemon 4.x for Home Assistant
-----------------------------------------------------------
 Add-on version: 0.7.0
 You are running the latest version of this add-on.
 System: Home Assistant OS 6.2  (aarch64 / raspberrypi4-64)
 Home Assistant Core: 2021.8.6
 Home Assistant Supervisor: 2021.09.0
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing... 
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] appdaemon.sh: executing... 
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/aarch64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/aarch64/APKINDEX.tar.gz
v3.14.2-11-gcd5ad8e85c [https://dl-cdn.alpinelinux.org/alpine/v3.14/main]
v3.14.2-17-ge254734c37 [https://dl-cdn.alpinelinux.org/alpine/v3.14/community]
OK: 14815 distinct packages available
(1/55) Installing sdl2 (2.0.14-r1)
(2/55) Installing libxau (1.0.9-r0)
(3/55) Installing libmd (1.0.3-r0)
(4/55) Installing libbsd (0.11.3-r0)
(5/55) Installing libxdmcp (1.1.3-r0)
(6/55) Installing libxcb (1.14-r2)
(7/55) Installing libx11 (1.7.2-r0)
(8/55) Installing aom-libs (1.0.0-r3)
(9/55) Installing alsa-lib (1.2.5-r2)
(10/55) Installing libpng (1.6.37-r1)
(11/55) Installing freetype (2.10.4-r1)
(12/55) Installing libuuid (2.37-r0)
(13/55) Installing fontconfig (2.13.1-r4)
(14/55) Installing fribidi (1.0.10-r0)
(15/55) Installing libintl (0.21-r0)
(16/55) Installing libblkid (2.37-r0)
(17/55) Installing libmount (2.37-r0)
(18/55) Installing pcre (8.44-r0)
(19/55) Installing glib (2.68.3-r0)
(20/55) Installing graphite2 (1.3.14-r0)
(21/55) Installing harfbuzz (2.8.1-r0)
(22/55) Installing libass (0.15.1-r0)
(23/55) Installing libdav1d (0.9.0-r0)
(24/55) Installing gmp (6.2.1-r0)
(25/55) Installing nettle (3.7.2-r0)
(26/55) Installing p11-kit (0.23.22-r0)
(27/55) Installing libtasn1 (4.17.0-r0)
(28/55) Installing libunistring (0.9.10-r1)
(29/55) Installing gnutls (3.7.1-r0)
(30/55) Installing lame (3.100-r0)
(31/55) Installing opus (1.3.1-r1)
(32/55) Installing libgomp (10.3.1_git20210424-r2)
(33/55) Installing soxr (0.1.3-r2)
(34/55) Installing libsrt (1.4.2-r0)
(35/55) Installing libssh (0.9.6-r0)
(36/55) Installing libogg (1.3.5-r0)
(37/55) Installing libtheora (1.1.1-r16)
(38/55) Installing libjpeg-turbo (2.1.0-r0)
(39/55) Installing v4l-utils-libs (1.20.0-r0)
(40/55) Installing libxext (1.3.4-r0)
(41/55) Installing libxfixes (6.0.0-r0)
(42/55) Installing libdrm (2.4.106-r0)
(43/55) Installing wayland-libs-client (1.19.0-r0)
(44/55) Installing libva (2.11.0-r0)
(45/55) Installing libvdpau (1.4-r0)
(46/55) Installing vidstab (1.1.0-r1)
(47/55) Installing libvorbis (1.3.7-r0)
(48/55) Installing libvpx (1.10.0-r0)
(49/55) Installing vulkan-loader (1.2.170-r1)
(50/55) Installing libwebp (1.2.0-r2)
(51/55) Installing x264-libs (20210211-r0)
(52/55) Installing x265-libs (3.4-r0)
(53/55) Installing xvidcore (1.3.7-r1)
(54/55) Installing ffmpeg-libs (4.4-r1)
(55/55) Installing ffmpeg (4.4-r1)
Executing busybox-1.33.1-r3.trigger
OK: 139 MiB in 119 packages
Looking in links: https://wheels.home-assistant.io/alpine-3.13/aarch64/
Collecting Pillow
  Downloading https://wheels.home-assistant.io/alpine-3.13/aarch64/Pillow-8.2.0-cp39-none-any.whl (534 kB)
Installing collected packages: Pillow
Successfully installed Pillow-8.2.0
[cont-init.d] appdaemon.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[15:37:41] INFO: Starting AppDaemon...

But when I run my app, I get errors loading the module. Here is my app and the AppDaemon Error log. If I comment out the PIL import the app initializes, so there is no other issue other than loading the module.

import hassapi as hass
from PIL import Image

class face_detected(hass.Hass):

  def initialize(self):
    self.listen_event(self.face_detected, "image_processing.detect_face")

  def face_detected(self, event, data, kwargs):
    self.log("%s with %d%% confidence", data["name"], data["confidence"] )

2021-09-05 15:28:21.690673 WARNING Error: ------------------------------------------------------------
2021-09-05 15:28:21.689257 WARNING Error: Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/appdaemon/app_management.py", line 970, in check_app_updates
    await utils.run_in_executor(self, self.read_app, mod["name"], mod["reload"])
  File "/usr/lib/python3.9/site-packages/appdaemon/utils.py", line 308, in run_in_executor
    response = future.result()
  File "/usr/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3.9/site-packages/appdaemon/app_management.py", line 747, in read_app
    importlib.reload(self.modules[module_name])
  File "/usr/lib/python3.9/importlib/__init__.py", line 169, in reload
    _bootstrap._exec(spec, module)
  File "", line 613, in _exec
  File "", line 855, in exec_module
  File "", line 228, in _call_with_frames_removed
  File "/config/appdaemon/apps/face_detected.py", line 2, in 
    from PIL import Image
  File "/usr/lib/python3.9/site-packages/PIL/Image.py", line 109, in 
    from . import _imaging as core
ImportError: cannot import name '_imaging' from 'PIL' (/usr/lib/python3.9/site-packages/PIL/__init__.py)

Hi there,

This seems to be related to this topic, but with Pillow instead of numpy.

Alpine has a system package called py3-pillow. So configuration should look like this:

system_packages:
  - py3-pillow
  - ffmpeg
python_packages: []
init_commands: []

As you can see Pillow should not be included as a python package, but as a system package now.

Regards,
Xavi M.

Thanks! That’s brilliant.
I’ve proposed a change to the documents since they happen to show Pillow as an example.

I now have another problem. I can’t access the camera data from home assistant (in the /media folder). I kind of feel stupid - of course, its a separate docker container.

Glad you got it working. I opened a PR to propose the change in the addon documentation: https://github.com/hassio-addons/addon-appdaemon/pull/151

I now have another problem. I can’t access the camera data from home assistant (in the /media folder). I kind of feel stupid - of course, its a separate docker container.

That I am not sure, but I believe that just /config is attached to the docker container.

Regards,

Yes, by my experiments only /config is available by default with the HASIO addon
That story is here Appdaemon 4 under HASSIO - how to read local file system - #4 by jasebob