How to install python pillow library in home assistant os?

Hello, I use home assistant Os on a raspberry pi. I’m trying to implement a command_line sensor that runs a python script. The .py file is in my /config folder. The script needs the pillow library, but when installing it gives an error “ModuleNotFoundError: No module named ‘distutils.cmd’”. Is there any way to install additional libraries in home assistant Os?

logs:
pip install Pillow
Traceback (most recent call last):
File “/usr/local/bin/pip”, line 5, in
from pip._internal.cli.main import main
File “/usr/local/lib/python3.9/dist-packages/pip/_internal/cli/main.py”, line 9, in
from pip._internal.cli.autocompletion import autocomplete
File “/usr/local/lib/python3.9/dist-packages/pip/_internal/cli/autocompletion.py”, line 10, in
from pip._internal.cli.main_parser import create_main_parser
File “/usr/local/lib/python3.9/dist-packages/pip/_internal/cli/main_parser.py”, line 8, in
from pip._internal.cli import cmdoptions
File “/usr/local/lib/python3.9/dist-packages/pip/_internal/cli/cmdoptions.py”, line 24, in
from pip._internal.cli.parser import ConfigOptionParser
File “/usr/local/lib/python3.9/dist-packages/pip/_internal/cli/parser.py”, line 12, in
from pip._internal.configuration import Configuration, ConfigurationError
File “/usr/local/lib/python3.9/dist-packages/pip/_internal/configuration.py”, line 26, in
from pip._internal.utils.logging import getLogger
File “/usr/local/lib/python3.9/dist-packages/pip/_internal/utils/logging.py”, line 29, in
from pip._internal.utils.misc import ensure_dir
File “/usr/local/lib/python3.9/dist-packages/pip/_internal/utils/misc.py”, line 42, in
from pip._internal.locations import get_major_minor_version
File “/usr/local/lib/python3.9/dist-packages/pip/_internal/locations/init.py”, line 14, in
from . import _distutils, _sysconfig
File “/usr/local/lib/python3.9/dist-packages/pip/_internal/locations/_distutils.py”, line 9, in
from distutils.cmd import Command as DistutilsCommand
ModuleNotFoundError: No module named ‘distutils.cmd’

I don’t know the answer, but from what I read, the distutils is part of the standard Python library, but is deprecated, and some linux distributions are no longer including it with their Python, so it could be that this is what is happening here.

If I had to guess a possible solution, you would have to go inside the home-assistant container and run something like #adk add python3.9-distutils. If this works, be aware you will have to redo this after each upgrade of HA.

2 Likes

It’s a little complicated, but hey… :smiley:

You need to add the following repository to your AddOn reps:

After adding it, you will be presented with some AddOns, the one you wan t is custom_deps.

Install it.

After that you can add custom dependencies to your HAos. It is, as the title of the repo suggests, an AddOn for developers to quickly test some deps.

I truely don’t know, if this survives a restart, but I assume. At least I don’t remember adding things after a restart while using the AddOn.

2 Likes

I am gettings an error when starting the addon.

Missing required option 'pypi' in Custom deps deployment (ae6e943c_custom_deps).
Running HA supervised in Docker under Debian on an Intel NUC.

Is there documentation on how to add the custom dependencies? e.g. do I place a requirements.txt file somewhere? I have verified the package I want to install is on Pypi.org. There doesn’t seem to be any docs anywhere on the GitHub site for custom_deps. But then again, I am new to all of this. :smiley:

Thanks - Todd

No, this is just for development purposes, so you have to do it by foot… :rofl: It is afterwards installed in your HA-OS installation and that’s it. As stated, it is for development.

Go to Settings > Add-ons > Custom deps deployment > Configuration > pypi and insert the packages you want. :slight_smile:

Thank you, I figured it out. When I first installed it, nothing was coming up under the “Configuration” menu, so I wasn’t sure what to do. I removed it and re-installed it, and it displayed the Configuration UI correctly.

1 Like

Reviving a one topic -sorry - but it’s the only place I have found an answer that might work so far.

If the python library is still in development in GitHub - can I use this add on to import it from there?

This is not listed in my installation :\