Yubico / yubikey-manager

Python library and command line tool for configuring any YubiKey over all USB interfaces.
https://developers.yubico.com/yubikey-manager/
BSD 2-Clause "Simplified" License
863 stars 125 forks source link

No package metadata was found for ykman : 5.5.1~ppa1~jammy1 apt install #626

Closed jutomation closed 1 month ago

jutomation commented 1 month ago

user@machine:$ apt-cache policy yubikey-manager

yubikey-manager: Installed: 5.5.1~ppa1~jammy1 Candidate: 5.5.1~ppa1~jammy1 Version table: *** 5.5.1~ppa1~jammy1 500 500 https://ppa.launchpadcontent.net/yubico/stable/ubuntu jammy/main amd64 Packages 100 /var/lib/dpkg/status 5.2.1-1 500 500 http://archive.ubuntu.com/ubuntu noble/universe amd64 Packages 500 http://archive.ubuntu.com/ubuntu noble/universe i386 Packages

user@machine:$ lsb_release -rd

No LSB modules are available.
Description:  Linux Mint 22
Release:  22

Bug description summary:

user@machine:$ ykman Traceback (most recent call last): File "/usr/lib/python3.12/importlib/metadata/init.py", line 397, in from_name return next(cls.discover(name=name)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/bin/ykman", line 33, in sys.exit(load_entry_point('ykman==5.5.1', 'console_scripts', 'ykman')()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/bin/ykman", line 22, in importlib_load_entry_point for entry_point in distribution(dist_name).entry_points ^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/importlib/metadata/init.py", line 862, in distribution return Distribution.from_name(distribution_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/importlib/metadata/init.py", line 399, in from_name raise PackageNotFoundError(name) importlib.metadata.PackageNotFoundError: No package metadata was found for ykman

Steps to reproduce

Scratch install of linux mint

sudo apt-add-repository ppa:yubico/stable
sudo apt update
sudo apt install yubikey-manager

Expected result

Ykman to display

jutomation commented 1 month ago

Please note this also happens on similarly version ubuntu machines. I use a test linux mint image to confirm all authentication for yubikeys before we upgrade our machines.

dainnilsson commented 1 month ago

I'm unable to reproduce this using a stock Ubuntu 22.04 image. I see that Python 3.12 is part of the path in your stacktrace, which isn't normally available in Ubuntu 22.04. Are you manually installing a newer Python version, and if so, through which method?

dainnilsson commented 1 month ago

I did a little digging and I am able to reproduce the issue by forcing ykman to use Python 3.12, which can happen if you for example change the /usr/bin/python3 binary on your system:

$ ls -lah /opt/venvs/yubikey-manager/bin/
total 52K
drwxr-xr-x 2 root root 4.0K Aug  5 12:53 .
drwxr-xr-x 5 root root 4.0K Aug  5 12:41 ..
-rw-r--r-- 1 root root 8.9K Jul  1 12:17 Activate.ps1
-rw-r--r-- 1 root root 2.0K Jul  1 12:17 activate
-rw-r--r-- 1 root root  941 Jul  1 12:17 activate.csh
-rw-r--r-- 1 root root 2.2K Jul  1 12:17 activate.fish
-rwxr-xr-x 1 root root  231 Jul  1 12:17 keyring
-rwxr-xr-x 1 root root  243 Jul  1 12:17 pip
-rwxr-xr-x 1 root root  243 Jul  1 12:17 pip3
-rwxr-xr-x 1 root root  243 Jul  1 12:17 pip3.10
lrwxrwxrwx 1 root root    7 Jul  1 12:17 python -> python3
lrwxrwxrwx 1 root root   16 Jul  1 12:17 python3 -> /usr/bin/python3
lrwxrwxrwx 1 root root    7 Jul  1 12:17 python3.10 -> python3
-rwxr-xr-x 1 root root  991 Aug  5 12:53 ykman

The PPA installation is tied to Python 3.10, so you will either have to manually adjust the symlink in /opt/venvs/yubikey-manager/bin/ to point to python3.10, or install yubikey-manager using a different method, such as pip.

jutomation commented 1 month ago

I'm unable to reproduce this using a stock Ubuntu 22.04 image. I see that Python 3.12 is part of the path in your stacktrace, which isn't normally available in Ubuntu 22.04. Are you manually installing a newer Python version, and if so, through which method?

Linut Mint 22 is based on Ubuntu 24.04. My installs with 22.04 everything does work correctly. The default python on the newer versions is 3.11<

Pip install is also broken (this is merely opinion and not fact). I understand this piece is nitpicking and it's stated in instructions pcslite is needed but for your average user I would explicitly put the commands/instructions on help pages or directly in the python package as a requires.

https://github.com/Yubico/yubikey-manager/blob/0c69ca83628cdd52a962b3d0c75700e5db3bfc8f/pyproject.toml#L29

Requires-Dist: click (>=8.0,<9.0)
Requires-Dist: cryptography (>=3.0,<45)
Requires-Dist: fido2 (>=1.0,<2.0)
Requires-Dist: keyring (>=23.4,<26)
Requires-Dist: pyscard (>=2.0,<3.0)
Requires-Dist: pywin32 (>=223) ; sys_platform == "win32"
$ pipx install yubikey-manager
Fatal error from pip prevented installation. Full pip output in file:
    /home/user/.local/state/pipx/log/cmd_2024-08-05_07.54.27_pip_errors.log

pip failed to build package:
    pyscard

Some possibly relevant errors from pip install:
    error: subprocess-exited-with-error
    Package libpcsclite was not found in the pkg-config search path.
    Package 'libpcsclite', required by 'virtual:world', not found
    smartcard/scard/helpers.c:28:10: fatal error: winscard.h: No such file or directory
    error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
    ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (pyscard)

Error installing yubikey-manager.

Pip Log

PIP STDERR
----------
  error: subprocess-exited-with-error

  × Building wheel for pyscard (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [23 lines of output]
      Package libpcsclite was not found in the pkg-config search path.
      Perhaps you should add the directory containing `libpcsclite.pc'
      to the PKG_CONFIG_PATH environment variable
      Package 'libpcsclite', required by 'virtual:world', not found
      /tmp/pip-build-env-__xe40m5/overlay/lib/python3.12/site-packages/setuptools/_distutils/dist.py:268: UserWarning: Unknown distribution option: 'test_suite'
        warnings.warn(msg)
      running bdist_wheel
      running build
      running build_py
      running build_ext
      building 'smartcard.scard._scard' extension
      swigging smartcard/scard/scard.i to smartcard/scard/scard_wrap.c
      swig -python -outdir smartcard/scard -DPCSCLITE -o smartcard/scard/scard_wrap.c smartcard/scard/scard.i
      creating build
      creating build/temp.linux-x86_64-cpython-312
      creating build/temp.linux-x86_64-cpython-312/smartcard
      creating build/temp.linux-x86_64-cpython-312/smartcard/scard
      x86_64-linux-gnu-gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O2 -Wall -fPIC -DVER_PRODUCTVERSION=2,0,10,0000 -DVER_PRODUCTVERSION_STR=2.0.10 -DPCSCLITE=1 -Ismartcard/scard/ -I/usr/include/PCSC -I/usr/local/include/PCSC -I/home/user/.local/share/pipx/venvs/yubikey-manager/include -I/usr/include/python3.12 -c smartcard/scard/helpers.c -o build/temp.linux-x86_64-cpython-312/smartcard/scard/helpers.o
      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

Installling libpcsclite manually will fix this.

apt install libpcsclite-dev
jutomation commented 1 month ago

Some of the above comments are for other users searching for the bug. I have a path forward for our upgrade process nonetheless.

dainnilsson commented 1 month ago

Ubuntu 24.04 (or derivatives) should use the correct PPA package, but your first post shows the package for jammy being installed rather than for noble. With a fresh Ubuntu 24.04 and the correct package installed the proper Python version will be used:

ls -lah /opt/venvs/yubikey-manager/bin/
total 52K
drwxr-xr-x 2 root root 4.0K Aug  5 14:56 .
drwxr-xr-x 5 root root 4.0K Aug  5 14:56 ..
-rw-r--r-- 1 root root 8.9K Jul  1 12:17 Activate.ps1
-rw-r--r-- 1 root root 2.2K Jul  1 12:17 activate
-rw-r--r-- 1 root root  942 Jul  1 12:17 activate.csh
-rw-r--r-- 1 root root 2.2K Jul  1 12:17 activate.fish
-rwxr-xr-x 1 root root  231 Jul  1 12:17 keyring
-rwxr-xr-x 1 root root  243 Jul  1 12:17 pip
-rwxr-xr-x 1 root root  243 Jul  1 12:17 pip3
-rwxr-xr-x 1 root root  243 Jul  1 12:17 pip3.12
lrwxrwxrwx 1 root root    7 Jul  1 12:17 python -> python3
lrwxrwxrwx 1 root root   16 Jul  1 12:17 python3 -> /usr/bin/python3
lrwxrwxrwx 1 root root    7 Jul  1 12:17 python3.12 -> python3
-rwxr-xr-x 1 root root  239 Jul  1 12:17 ykman
jutomation commented 1 month ago

@dainnilsson Great catch! I've been staring at packages for the last 3 days and missed this. Ignore my earlier comments, this wasn't even coming up in package options.

Probably a bork during mint 21 -> 22 upgrade.