Installing pyscard with Python 3+ on macOS

By | April 29, 2023

In 2020, I did some reading and writing Python code to read NSICCS (National Standard for Indonesia Chip Card Specification) using USB SmartCard Reader Gemalto PC Twin Reader. This was possible using pyscard v1.9.9 with Python 2.7.

I just realized that the library was installed on my old MacBook Pro Retina 2012 and has not been installed on the recent MacBook. Of course, Python 2.7 is obsolete (for me), and the standard in this MacBook Pro is Python 3.8. Using pip, I encountered error like this:

❯ python3 -m pip install pyscard
Defaulting to user installation because normal site-packages is not writeable
Collecting pyscard
  Using cached pyscard-2.0.7.tar.gz (152 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: pyscard
  Building wheel for pyscard (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for pyscard (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [8 lines of output]
      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 -D__APPLE__ -o smartcard/scard/scard_wrap.c smartcard/scard/scard.i
      error: command 'swig' failed: No such file or directory
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pyscard
Failed to build pyscard
ERROR: Could not build wheels for pyscard, which is required to install pyproject.toml-based projects

I noticed that there was at least an error mentioning about swig. So, using I installed it using brew

> brew install swig
Running `brew update --auto-update`...
==> Downloading https://ghcr.io/v2/homebrew/portable-ruby/portable-ruby/blobs/sha256:61029cec31c68a1fae1fa90fa876adf43d0becff777da793f9b5c5577f00567a
########################################################################################################################### 100.0%
==> Pouring portable-ruby-2.6.10_1.el_capitan.bottle.tar.gz
==> Auto-updated Homebrew!
==> Fetching swig
==> Downloading https://ghcr.io/v2/homebrew/core/swig/manifests/4.1.1
########################################################################################################################### 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/swig/blobs/sha256:7762910a737820dc734b089253c2f5bc7140673a2300acd97f0338ebc7ef6fd
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:7762910a737820dc734b089253c2f5bc7140673a2300a
########################################################################################################################### 100.0%
==> Pouring swig--4.1.1.monterey.bottle.tar.gz
🍺  /usr/local/Cellar/swig/4.1.1: 775 files, 5.6MB
==> Running `brew cleanup swig`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

After it is installed, then re-run the pip again:

❯ python3 -m pip install pyscard
Defaulting to user installation because normal site-packages is not writeable
Collecting pyscard
  Using cached pyscard-2.0.7.tar.gz (152 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: pyscard
  Building wheel for pyscard (pyproject.toml) ... done
  Created wheel for pyscard: filename=pyscard-2.0.7-cp38-cp38-macosx_10_9_x86_64.whl size=139982 sha256=caf4631a8ec2c4b0418577be2bb6410db4b57ca12b9616ceef954ab29407eac4
  Stored in directory: /Users/tintinnya/Library/Caches/pip/wheels/e6/e1/66/2a8da9068aab2bed6d5079670b6ee3ab46d2a61a5f98da7a7e
Successfully built pyscard
Installing collected packages: pyscard
Successfully installed pyscard-2.0.7

And, it’s done! Python 3.8.10 can use the pyscard library on macOS 12.6.5

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.