waveform80 / rpi-lgpio

A compatibility shim for lgpio emulating the RPi.GPIO API
https://rpi-lgpio.readthedocs.io/
Other
13 stars 8 forks source link

Error Installing rpi-lgpio on Docker #12

Open velison1-mbed opened 6 months ago

velison1-mbed commented 6 months ago

I am attempting to dockerize my Python project on a Raspberry Pi Zero W. I am using the balenalib/raspberry-pi-python:3.11.2-bookworm-build base image. When I try to install the rpi-lgpio package, I encounter an error. Here are the details of the error:

root@4bd50d6fa8b4:/app# pip install --verbose rpi-lgpio
Using pip 24.0 from /usr/local/lib/python3.11/site-packages/pip (python 3.11)
Collecting rpi-lgpio
  Obtaining dependency information for rpi-lgpio from https://files.pythonhosted.org/packages/da/a9/06b843528e47ded0dd276537e9c56e7aec7c841b3b2749274e7d8121dab5/rpi_lgpio-0.6-py3-none-any.whl.metadata
  Using cached rpi_lgpio-0.6-py3-none-any.whl.metadata (2.5 kB)
Collecting lgpio>=0.1.0.1 (from rpi-lgpio)
  Using cached lgpio-0.2.2.0.tar.gz (90 kB)
  Running command python setup.py egg_info
  running egg_info
  creating /tmp/pip-pip-egg-info-uas1n4ze/lgpio.egg-info
  writing /tmp/pip-pip-egg-info-uas1n4ze/lgpio.egg-info/PKG-INFO
  writing dependency_links to /tmp/pip-pip-egg-info-uas1n4ze/lgpio.egg-info/dependency_links.txt
  writing top-level names to /tmp/pip-pip-egg-info-uas1n4ze/lgpio.egg-info/top_level.txt
  writing manifest file '/tmp/pip-pip-egg-info-uas1n4ze/lgpio.egg-info/SOURCES.txt'
  file lgpio.py (for module lgpio) not found
  reading manifest file '/tmp/pip-pip-egg-info-uas1n4ze/lgpio.egg-info/SOURCES.txt'
  reading manifest template 'MANIFEST.in'
  adding license file 'LICENSE'
  writing manifest file '/tmp/pip-pip-egg-info-uas1n4ze/lgpio.egg-info/SOURCES.txt'
  Preparing metadata (setup.py) ... done
Using cached rpi_lgpio-0.6-py3-none-any.whl (11 kB)
Building wheels for collected packages: lgpio
  Running command python setup.py bdist_wheel
  running bdist_wheel
  running build
  running build_py
  running build_ext
  building '_lgpio' extension
  swigging lgpio.i to lgpio_wrap.c
  swig -python -o lgpio_wrap.c lgpio.i
  creating build
  creating build/temp.linux-armv6l-cpython-311
  gcc -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -Isrc -I/usr/local/include/python3.11 -c lgpio_wrap.c -o build/temp.linux-armv6l-cpython-311/lgpio_wrap.o
  creating build/lib.linux-armv6l-cpython-311
  gcc -shared build/temp.linux-armv6l-cpython-311/lgpio_wrap.o -L/usr/local/lib -llgpio -o build/lib.linux-armv6l-cpython-311/_lgpio.cpython-311-arm-linux-gnueabihf.so
  /usr/bin/ld: cannot find -llgpio: No such file or directory
  collect2: error: ld returned 1 exit status
  error: command '/usr/bin/gcc' failed with exit code 1
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> See above for output.

  note: This error originates from a subprocess, and is likely not a problem with pip.
  full command: /usr/local/bin/python3 -u -c '
  exec(compile('"'"''"'"''"'"'
  # This is <pip-setuptools-caller> -- a caller that pip uses to run setup.py
  #
  # - It imports setuptools before invoking setup.py, to enable projects that directly
  #   import from `distutils.core` to work with newer packaging standards.
  # - It provides a clear error message when setuptools is not installed.
  # - It sets `sys.argv[0]` to the underlying `setup.py`, when invoking `setup.py` so
  #   setuptools doesn'"'"'t think the script is `-c`. This avoids the following warning:
  #     manifest_maker: standard file '"'"'-c'"'"' not found".
  # - It generates a shim setup.py, for handling setup.cfg-only projects.
  import os, sys, tokenize

  try:
      import setuptools
  except ImportError as error:
      print(
          "ERROR: Can not execute `setup.py` since setuptools is not available in "
          "the build environment.",
          file=sys.stderr,
      )
      sys.exit(1)

  __file__ = %r
  sys.argv[0] = __file__

  if os.path.exists(__file__):
      filename = __file__
      with tokenize.open(__file__) as f:
          setup_py_code = f.read()
  else:
      filename = "<auto-generated setuptools caller>"
      setup_py_code = "from setuptools import setup; setup()"

  exec(compile(setup_py_code, filename, "exec"))
  '"'"''"'"''"'"' % ('"'"'/tmp/pip-install-o0xwy5se/lgpio_a99ef0808f094905a2030ba54fbf62ed/setup.py'"'"',), "<pip-setuptools-caller>", "exec"))' bdist_wheel -d /tmp/pip-wheel-w43ivpe5
  cwd: /tmp/pip-install-o0xwy5se/lgpio_a99ef0808f094905a2030ba54fbf62ed/
  Building wheel for lgpio (setup.py) ... error
  ERROR: Failed building wheel for lgpio
  Running setup.py clean for lgpio
  Running command python setup.py clean
  running clean
  removing 'build/temp.linux-armv6l-cpython-311' (and everything under it)
  removing 'build/lib.linux-armv6l-cpython-311' (and everything under it)
  'build/bdist.linux-armv6l' does not exist -- can't clean it
  'build/scripts-3.11' does not exist -- can't clean it
  removing 'build'
Failed to build lgpio
ERROR: Could not build wheels for lgpio, which is required to install pyproject.toml-based projects
waveform80 commented 6 months ago

Ohhh, arm6l. Of course, I'd forgotten that arch...

Note to self: check the "arm7l" wheels to see if they're actually arm6l; if not, rebuild on raspios on a true arm6l board

Ed1ks commented 6 months ago

I have installed swig with dockerfile and it fails building for arm64:

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

# Install system dependencies for PyAudio, evdev, and build tools
RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc \
    portaudio19-dev \
    libevdev-dev \
    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

# 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", "/pi-audio-recorder/config/supervisord_docker.conf"]
252.2   Building wheel for lgpio (setup.py): finished with status 'error'
252.2   error: subprocess-exited-with-error
252.2
252.2   × python setup.py bdist_wheel did not run successfully.
252.2   │ exit code: 1
252.2   ╰─> [15 lines of output]
252.2       running bdist_wheel
252.2       running build
252.2       running build_py
252.2       running build_ext
252.2       building '_lgpio' extension
252.2       swigging lgpio.i to lgpio_wrap.c
252.2       swig -python -o lgpio_wrap.c lgpio.i
252.2       creating build
252.2       creating build/temp.linux-aarch64-cpython-311
252.2       gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -Isrc -I/usr/local/include/python3.11 -c lgpio_wrap.c -o build/temp.linux-aarch64-cpython-311/lgpio_wrap.o
252.2       creating build/lib.linux-aarch64-cpython-311
252.2       gcc -pthread -shared build/temp.linux-aarch64-cpython-311/lgpio_wrap.o -L/usr/local/lib -llgpio -o build/lib.linux-aarch64-cpython-311/_lgpio.cpython-311-aarch64-linux-gnu.so
252.2       /usr/bin/ld: cannot find -llgpio
252.2       collect2: error: ld returned 1 exit status
252.2       error: command '/usr/bin/gcc' failed with exit code 1
252.2       [end of output]
252.2
252.2   note: This error originates from a subprocess, and is likely not a problem with pip.
252.2   ERROR: Failed building wheel for lgpio
252.2   Running setup.py clean for lgpio
MrMisc-17 commented 5 months ago

@Ed1ks I noticed this line:

/usr/bin/ld: cannot find -llgpio

I had the same problem when trying to migrate my project from rpi3 to rpi4, and the only thing that worked was installing the lgpio module, following the instructions found here: https://abyz.me.uk/lg/download.html

Hope this helps!

plimptm commented 5 months ago

Ohhh, arm6l. Of course, I'd forgotten that arch...

Note to self: check the "arm7l" wheels to see if they're actually arm6l; if not, rebuild on raspios on a true arm6l board

I just hit the same issue trying to install the lgpio package on a pi zero w (also armv6l). I had to do a pip install swig since there appear to be dependency issues with the debian swig package.

$ pip install rpi-lgpio
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting rpi-lgpio
  Using cached https://www.piwheels.org/simple/rpi-lgpio/rpi_lgpio-0.6-py3-none-any.whl (11 kB)
Collecting lgpio>=0.1.0.1 (from rpi-lgpio)
  Using cached lgpio-0.2.2.0.tar.gz (90 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: lgpio
  Building wheel for lgpio (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [15 lines of output]
      running bdist_wheel
      running build
      running build_py
      running build_ext
      building '_lgpio' extension
      swigging lgpio.i to lgpio_wrap.c
      swig -python -o lgpio_wrap.c lgpio.i
      creating build
      creating build/temp.linux-armv6l-cpython-311
      arm-linux-gnueabihf-gcc -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Isrc -I/home/pi/RPi-Jukebox-RFID/.venv/include -I/usr/include/python3.11 -c lgpio_wrap.c -o build/temp.linux-armv6l-cpython-311/lgpio_wrap.o
      creating build/lib.linux-armv6l-cpython-311
      arm-linux-gnueabihf-gcc -shared -Wl,-O1 -Wl,-Bsymbolic-functions -g -fwrapv -O2 build/temp.linux-armv6l-cpython-311/lgpio_wrap.o -L/usr/lib/arm-linux-gnueabihf -llgpio -o build/lib.linux-armv6l-cpython-311/_lgpio.cpython-311-arm-linux-gnueabihf.so
      /usr/bin/ld: cannot find -llgpio: No such file or directory
      collect2: error: ld returned 1 exit status
      error: command '/usr/bin/arm-linux-gnueabihf-gcc' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for lgpio
  Running setup.py clean for lgpio
Failed to build lgpio
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (lgpio)