Gadgetoid / PY_LGPIO

Python packaging for the PY_LGPIO lg bindings.
https://github.com/joan2937/lg
The Unlicense
1 stars 1 forks source link

Please make Pull Request in official Rep #2

Open Ed1ks opened 3 months ago

Ed1ks commented 3 months ago

Hello, and thank you for your great Work @Gadgetoid

This repo is a nice workaround for people who need GPIO inside Docker for Raspberry Pi 5.

But please consider creating a Pull request in official Repo: https://github.com/joan2937/lg/pulls

So maybe it will accepted and you got the official lgpio repaired.

Gadgetoid commented 3 months ago

I tried 😭

Actual packaging and distribution of lg is handled by others, and there's a fork where I brought a PR attempting to solve this problem to their attention: https://github.com/gpiozero/lg/pull/1

I think this repository is about the closest you'll get to a solution. I suppose we could huck it up onto PyPI under another name 😆 Though I'd rather work with and not against my peers.

Ed1ks commented 3 months ago

While being happy that the package got installed and creating this post, I got another issue, that I get error when using gpiozero in python code:

/usr/local/lib/python3.11/site-packages/gpiozero/devices.py:300: PinFactoryFallback: Falling back from lgpio: No module named 'lgpio'
  warnings.warn(
/usr/local/lib/python3.11/site-packages/gpiozero/devices.py:300: PinFactoryFallback: Falling back from rpigpio: No module named 'RPi'
  warnings.warn(
/usr/local/lib/python3.11/site-packages/gpiozero/devices.py:300: PinFactoryFallback: Falling back from pigpio: No module named 'pigpio'
  warnings.warn(
/usr/local/lib/python3.11/site-packages/gpiozero/devices.py:300: PinFactoryFallback: Falling back from native: unable to open /dev/gpiomem or /dev/mem; upgrade your kernel or run as root

this is my dockerfile:

FROM python:3.11-slim-bullseye
ENV PYTHONUNBUFFERED=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PUID=1000\
    PGID=1000

# Set the working directory inside the container
WORKDIR /app

# Create and set volumes

# Install system dependencies for PyAudio, evdev, and build tools
RUN apt-get update && apt-get install -y --no-install-recommends \
    supervisor \
    swig \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements.txt to the container and install Python dependencies
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

RUN pip install pigpio gpio gpiozero
RUN pip install https://github.com/Gadgetoid/PY_LGPIO/releases/download/0.2.2.0/lgpio-0.2.2.0.tar.gz

# Copy the rest of the application code to the container
COPY . .

# Ensure the entrypoint script is executable
RUN chmod +x ./entrypoint.sh

# Expose the port the app runs on
EXPOSE 8010

ENTRYPOINT ["./entrypoint.sh"]
CMD ["supervisord", "-c", "/supervisord_docker.conf"]

the code runs fine on Raspberry Pi 5 root, but if running docker container with priviliged mode, it doesnt seem to work. Any Ideas, whats wrong?