Nitrokey / pynitrokey

Python client for Nitrokey devices
Apache License 2.0
103 stars 28 forks source link

During pipx upgrade on Debian: `fatal error: winscard.h: No such file or directory` #579

Open farblos opened 4 weeks ago

farblos commented 4 weeks ago

I get the following error from pynitrokey during pipx upgrade-all

[~]$ pipx upgrade-all
  error: subprocess-exited-with-error

  × Building wheel for pyscard (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [14 lines of output]
      running bdist_wheel
      running build
      running build_py
      running build_ext
      building 'smartcard.scard._scard' extension
      swigging src/smartcard/scard/scard.i to src/smartcard/scard/scard_wrap.c
      swig -python -outdir src/smartcard/scard -DPCSCLITE -o src/smartcard/scard/scard_wrap.c src/smartcard/scard/scard.i
      creating build/temp.linux-x86_64-cpython-312/src/smartcard/scard
      x86_64-linux-gnu-gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O2 -Wall -fPIC -DVER_PRODUCTVERSION=2,2,0,0000 -DVER_PRODUCTVERSION_STR=2.2.0 -DPCSCLITE=1 -Isrc/smartcard/scard/ -I/usr/include/PCSC -I/usr/local/include/PCSC -I/home/farblos/.local/share/pipx/venvs/pynitrokey/include -I/usr/include/python3.12 -c src/smartcard/scard/helpers.c -o build/temp.linux-x86_64-cpython-312/src/smartcard/scard/helpers.o
      src/smartcard/scard/helpers.c:28:10: fatal error: winscard.h: No such file or directory
         28 | #include <winscard.h>
            |          ^~~~~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/x86_64-linux-gnu-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 pyscard
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (pyscard)
'/home/farblos/.local/share/pipx/venvs/pynitrokey/bin/python -m pip
--no-input install --upgrade pynitrokey -q' failed
No packages upgraded after running 'pipx upgrade-all' 😴
The following package(s) failed to upgrade: pynitrokey

Version information:

[~]$ uname -a
Linux host01 6.11.2-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.11.2-1 (2024-10-05) x86_64 GNU/Linux

[~]$ python3 --version
Python 3.12.6

[~]$ cat /etc/debian_version 
trixie/sid

[~]$ pipx list
venvs are in /home/farblos/.local/share/pipx/venvs
apps are exposed on your $PATH at /home/farblos/.local/bin
manual pages are exposed at /home/farblos/.local/share/man
   package pynitrokey 0.4.50, installed using Python 3.12.4
    - nitropy

There does not seem to be a canonical candidate package providing winscard.h on Debian, plus I'm more or less Python-agnostic, so any help appreciated.

robin-nitrokey commented 4 weeks ago

Installing libpcsclite-dev should fix this issue on Debian. But it’s not nice that you need to install additional libraries to get pynitrokey to install properly. Maybe we can put the piv command that depends on pyscard behind an optional extra to make installation easier for those users that are not interested in PIV.

farblos commented 4 weeks ago

@robin-nitrokey, thanks for your quick reply and action on this. Installing libpcsclite-dev indeeds works around the above error, but then the compile fails on Python.h, so your fix will be most appreciated.

For reference and searching, here the error message related to Python.h (and no, I'd rather not install more header files - will wait for your fix :-):

[~]$ pipx upgrade-all
  error: subprocess-exited-with-error

  × Building wheel for pyscard (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [14 lines of output]
      running bdist_wheel
      running build
      running build_py
      running build_ext
      building 'smartcard.scard._scard' extension
      swigging src/smartcard/scard/scard.i to src/smartcard/scard/scard_wrap.c
      swig -python -outdir src/smartcard/scard -DPCSCLITE -o src/smartcard/scard/scard_wrap.c src/smartcard/scard/scard.i
      creating build/temp.linux-x86_64-cpython-312/src/smartcard/scard
      x86_64-linux-gnu-gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O2 -Wall -fPIC -DVER_PRODUCTVERSION=2,2,0,0000 -DVER_PRODUCTVERSION_STR=2.2.0 -DPCSCLITE=1 -Isrc/smartcard/scard/ -I/usr/include/PCSC -I/usr/local/include/PCSC -I/home/farblos/.local/share/pipx/venvs/pynitrokey/include -I/usr/include/python3.12 -c src/smartcard/scard/helpers.c -o build/temp.linux-x86_64-cpython-312/src/smartcard/scard/helpers.o
      src/smartcard/scard/helpers.c:31:10: fatal error: Python.h: No such file or directory
         31 | #include <Python.h>
            |          ^~~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/x86_64-linux-gnu-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 pyscard
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (pyscard)
'/home/farblos/.local/share/pipx/venvs/pynitrokey/bin/python -m pip
--no-input install --upgrade pynitrokey -q' failed
No packages upgraded after running 'pipx upgrade-all' 😴
The following package(s) failed to upgrade: pynitrokey
robin-nitrokey commented 4 weeks ago

For reference, python3-dev should be the relevant package. Overall, on Debian-based systems, the packages libpcsclite-dev, python3-dev, gcc and swig should be sufficient.

bocekm commented 3 weeks ago

I faced the same issue on Fedora 41 and fixed it by running $ sudo dnf install pcsc-lite-devel python3-devel. Related: https://github.com/LudovicRousseau/pyscard/issues/218.