WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Help installing the spidev module  (Read 328 times)

Offline creitzel

  • Newbie
  • *
  • Posts: 41
Help installing the spidev module
« on: September 02, 2024, 07:36:16 PM »
Hello,

I have been trying to get the spidev module installed on my Pi Zero W running PiCore 14.  I need it for a project I'm currently working on.

Unfortunately, the module contains c code, which means that pip needs to build that c code when installing the module, and it is failing while trying to build it.

Here's a dump of how the install/compile attempt looks:

Code: [Select]
tc@binclck:~$ pip install spidev

Defaulting to user installation because normal site-packages is not writeable
Collecting spidev
  Using cached spidev-3.6.tar.gz (11 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: spidev
  Building wheel for spidev (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for spidev (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [28 lines of output]
      /tmp/pip-build-env-2cixurlr/overlay/lib/python3.11/site-packages/setuptools/dist.py:452: SetuptoolsDeprecationWarning: Invalid dash-separated options
      !!

              ********************************************************************************
              Usage of dash-separated 'description-file' will not be supported in future
              versions. Please use the underscore name 'description_file' instead.

              By 2024-Sep-26, you need to update your project and remove deprecated calls
              or your builds will no longer be supported.

              See https://setuptools.pypa.io/en/latest/userguide/declarative_config.html for details.
              ********************************************************************************

      !!
        opt = self.warn_dash_deprecation(opt, section)
      running bdist_wheel
      running build
      running build_ext
      building 'spidev' extension
      creating build
      creating build/temp.linux-armv6l-cpython-311
      gcc -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Os -pipe -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -I/usr/local/include/ncursesw -Os -pipe -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -I/usr/local/include/ncursesw -fPIC -I/usr/local/include/python3.11 -c spidev_module.c -o build/temp.linux-armv6l-cpython-311/spidev_module.o
      In file included from spidev_module.c:28:
      /usr/local/include/python3.11/Python.h:23:12: fatal error: stdlib.h: No such file or directory
         23 | #  include <stdlib.h>
            |            ^~~~~~~~~~
      compilation terminated.
      error: command '/usr/local/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
Failed to build spidev
ERROR: Could not build wheels for spidev, which is required to install pyproject.toml-based projects

As you can see from the output, it is having trouble finding stdlib.h, which I know is part of the normal gcc install.  I think I have all of the appropriate tcz's loaded, here's the list:

Code: [Select]
tc@binclck:~$ tce-status -i
binutils
bzip2
bzip2-dev
bzip2-lib
ca-certificates
file
firmware-rpi-wifi
flex
gcc
gdbm
gdbm-dev
gmp
isl
liblz4
liblzma
liblzma-dev
libnl
libzstd
mpc
mpfr
nano
ncurses
ncurses-dev
ncurses-terminfo
openssh
openssl
openssl-dev
python3.11
python3.11-dev
python3.11-pip
readline
readline-dev
regdb
sqlite3
sqlite3-dev
unzip
wifi
wireless-6.1.68-piCore
wireless_tools
wpa_supplicant
zstd

And with this set of tcz's loaded, stdlib.h appears to be present on the file system:

Code: [Select]
tc@binclck:~$ cd /
tc@binclck:/$ sudo find -name "stdlib*"
./usr/local/include/c++/12.2.0/tr1/stdlib.h
./usr/local/include/c++/12.2.0/stdlib.h
./tmp/tcloop/gcc/usr/local/include/c++/12.2.0/stdlib.h
./tmp/tcloop/gcc/usr/local/include/c++/12.2.0/tr1/stdlib.h

I'm not sure why gcc can't seem to find it.  What am I missing here?

Offline creitzel

  • Newbie
  • *
  • Posts: 41
Re: Help installing the spidev module
« Reply #1 on: September 02, 2024, 08:28:23 PM »
ok, so after poking around on the internet a bit, I came across a post where someone was having the same problem as me.  Following some of the steps in that post, I have identified the pre-processor being used with the following:

Code: [Select]
tc@binclck:~$ gcc -print-prog-name=cc1

/tmp/tcloop/gcc/usr/local/bin/../lib/gcc/armv7l-unknown-linux-gnueabihf/12.2.0/cc1

and then using that I was able to find the search path that gcc is using for include files:

Code: [Select]
tc@binclck:/usr/local/lib/gcc/armv7l-unknown-linux-gnueabihf/12.2.0$ ./cc1 -v

ignoring nonexistent directory "/usr/local/lib/gcc/armv7l-unknown-linux-gnueabihf/12.2.0/../../../../armv7l-unknown-linux-gnueabihf/include"
ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/lib/gcc/armv7l-unknown-linux-gnueabihf/12.2.0/include
 /usr/local/include
 /usr/local/lib/gcc/armv7l-unknown-linux-gnueabihf/12.2.0/include-fixed
End of search list.
^C

so it looks like gcc is looking in the wrong place for my include file.  That said, I'm not sure how to remedy it.  pip is setting up the compiler options, and I think that is where I would have to make changes to have them take effect for this build.

I'm pretty new to building c code via pip, and building c code in general, so any advice you more experienced guys could give me would be greatly appreciated.  :-)

Offline creitzel

  • Newbie
  • *
  • Posts: 41
Re: Help installing the spidev module
« Reply #2 on: September 02, 2024, 08:43:00 PM »
Now that I'm thinking about this more, those include directory names are suspicious to me.  They all include
Quote
armv7l-...
.  Isn't the pi zero W an armv6?  Maybe I don't have the right tcz's loaded.  I pulled them from the piCore 14 repo, but maybe I need older versions? 

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11518
Re: Help installing the spidev module
« Reply #3 on: September 02, 2024, 09:28:12 PM »
Hi creitzel
I think you are missing  glibc_base-dev.tcz.
I also noticed  compiletc.tcz  is absent from your list.
Installing  compiletc.tcz  is the proper way to install the
tools required for compiling, including  glibc_base-dev.tcz.

Offline creitzel

  • Newbie
  • *
  • Posts: 41
Re: Help installing the spidev module
« Reply #4 on: September 02, 2024, 09:35:01 PM »
DOH

Good catch Rich.  I downloaded it, and have it installed, but I didn't load it when trying to install the module.

I'm retrying right now, with it loaded.  :-)


Offline creitzel

  • Newbie
  • *
  • Posts: 41
Re: Help installing the spidev module
« Reply #5 on: September 02, 2024, 09:42:27 PM »
Yep that was it Rich. 

Man do I feel stupid lol. 

I loaded compiletc and gcc works fine now.  I've been beating my head against this wall for a few hours now.  I was starting to think I was going nuts.  I know I've built binaries with piCore before, and never ran into anything like this.  lol

Sorry to bug ya.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11518
Re: Help installing the spidev module
« Reply #6 on: September 02, 2024, 09:52:12 PM »
Hi creitzel
... Sorry to bug ya.
No Worries. You're not the first person to do this, you
won't be the last. :)