pimoroni / fanshim-python

Python library for the Fan SHIM for Raspberry Pi
https://shop.pimoroni.com/products/fan-shim
MIT License
295 stars 85 forks source link

Fanshim installation fails on Alpine Linux aarch64 #111

Closed cmonty14 closed 1 year ago

cmonty14 commented 2 years ago

Hello, I have installed Alpine Linux aarch64 on RPi 4 and now I want to deploy software and config for Fanshim. Fanshim has some Python dependencies of which one is Spidev.

I'm using this command pip install spidev for Python Spidev installation fails with this error:

Defaulting to user installation because normal site-packages is not
writeable
Collecting spidev     
  Using cached spidev-3.5.tar.gz (10 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: spidev
  Building wheel for spidev (setup.py) ... error
  error:
subprocess-exited-with-error                                           

  × python setup.py bdist_wheel did not run successfully.
  │ exit code:
1                                                                                                                                              

  ╰─> [14 lines of
output]                                                      
      /usr/lib/python3.10/site-packages/setuptools/dist.py:717:
UserWarning: Usage of dash-separated 'description-file' will not be
supported in future versions
. Please use the underscore name 'description_file' instead

warnings.warn(                                                          
      running bdist_wheel
      running build
      running
build_ext                                                                                                                                       

      building 'spidev' extension
      creating build
      creating build/temp.linux-aarch64-3.10        
      gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3
-Wall -g -g -g -DTHREAD_STACK_SIZE=0x100000 -fPIC
-I/usr/include/python3.10 -c spidev_module
.c -o build/temp.linux-aarch64-3.10/spidev_module.o
      spidev_module.c:33:10: fatal error: linux/spi/spidev.h: No such
file or directory
         33 | #include <linux/spi/spidev.h>
            |          ^~~~~~~~~~~~~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/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 spidev
  Running setup.py clean for spidev
Failed to build spidev
Installing collected packages: spidev
  Running setup.py install for spidev ... error
  error: subprocess-exited-with-error

  × Running setup.py install for spidev did not run successfully.
  │ exit code: 1
  ╰─> [16 lines of output]
      /usr/lib/python3.10/site-packages/setuptools/dist.py:717:
UserWarning: Usage of dash-separated 'description-file' will not be
supported in future versions
. Please use the underscore name 'description_file' instead
        warnings.warn(
      running install

/usr/lib/python3.10/site-packages/setuptools/command/install.py:34:
SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build
and pip and ot
her standards-based tools.
        warnings.warn(
      running build
      running build_ext
      building 'spidev' extension
      creating build
      creating build/temp.linux-aarch64-3.10
      gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3
-Wall -g -g -g -DTHREAD_STACK_SIZE=0x100000 -fPIC
-I/usr/include/python3.10 -c spidev_module
.c -o build/temp.linux-aarch64-3.10/spidev_module.o
      spidev_module.c:33:10: fatal error: linux/spi/spidev.h: No such
file or directory
         33 | #include <linux/spi/spidev.h>
            |          ^~~~~~~~~~~~~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/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: legacy-install-failure

× Encountered error while trying to install package.
╰─> spidev

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

Can you please advise how to fix this issue?

This error is not reproducible on Debian, though.

THX Thomas

hsellik commented 2 years ago

Faced a similar issue on a Raspberry Pi 4 with Home Assistant OS (arch).

I believe the error can be solved by running: apk add linux-headers

I also had to modify the install script and change: CODENAME='lsb_release -sc' to CODENAME="bullseye" since I am using Python 3 and lsb_release command is not supported.

The full list of commands I executed to make it work was:

apk add linux-headers
apk add build-base
apk add --no-cache python3 py3-pip
apk add python3-dev
pip3 install spidev
./install.sh

Note to Home Assistant users: Originally, I started messing with the script in this repo because native rpi gpio integration was removed in HA version 2022.6. However, you can still use the HACS custom integration: https://github.com/thecode/ha-rpi_gpio