Import python hidapi module in (alpine linux) — > ModuleNotFoundError: No module named ‘hid’

  alpine, docker, import, linux, python

I am trying to access my weather station via USB with python in a HomeAssistant-Docker container. But I am failing to import the neccessary hidapi-module. How can I import hidapi with python in alpine linux?

Unfortunately, with alpine linux (home assistant) the "pip install hidapi" command results in an error, because of wheel not working with alpine linux.

My docker-compose.yaml:

version: '3'
    container_name: homeassistant
    build: .
      - ./homeassistant:/config
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    privileged: true
    network_mode: host

My Dockerfile:

RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python
RUN python3 -m ensurepip
RUN pip3 install --no-cache --upgrade pip setuptools
RUN apk add py3-hidapi
RUN apk add libusb-dev
RUN apk add hidapi

The hid-module gets sucessfully installed and is found here:


I have the python search path configured:

export PYTHONPATH="/usr/lib/python3.9/site-packages"

python command:

python -c "import hid"

–> ModuleNotFoundError: No module named ‘hid’

It’s running on a raspberry pi.

Source: Docker Questions