Adafruit Blinka is a CircuitPython compatability layer for standard Python (CPython) on desktops, laptops, and single board computers. Installing Blinka is a great way to access the hardware drivers and other helpers available in CircuitPython. For example, CP has a very nice interface to Bluetooth LE that can make setting up your laptop as a central device much easier!
See Adafruit's installation guide for more details on setting up Blinka. You might also want to tale a look at the guides below for methods for setting up Blinka with computers for hardware hacking:
- https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221
- https://learn.adafruit.com/circuitpython-on-any-computer-with-ft232h
The guides referenced above will give you some idea of how to install Blinka, but if you want to get the most bang for your buck, there are some additional dependencies that you're going to want to install.
- Xcode Command Line Tools - You may already have this installed, as they're a core dependency for software dev on MacOS. This is the command line companion to the Xcode IDE.
- Homebrew - a package manager for MacOS (and Linux!). Makes installing stuff and keeping it up to date much easier. Homebrew makes your Mac better and if you do any kind of technincal work, you probably already have it.
- pyenv - Python version management. pyenv and it's plugins make it easy to install and manage different versions of Python on your system. Why would you want this, when MacOS has Python installed by default (and Homebrew can install Python, too)? Because pyenv gives you control over the exact versions installed, simple switching between versions, and just general awesomeness
- Build dependencies for Python - you'll be installing Python with pyenv, and you'll need these tools to make that work.
I have copied the install steps from the various sources, but you should consider checking the linked resources to confirm that this is up to date.
# install Xcode Command Line Tools
xcode-select --install
# install Homebrew - https://brew.sh/
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# install python build dependencies https://github.com/pyenv/pyenv/wiki#suggested-build-environment
brew install openssl readline sqlite3 xz zlib tcl-tk@8
# install pyenv and pyenv-virtualenv - https://github.com/pyenv/pyenv
brew install pyenv pyenv-virtualenv
# install a modern Python and then make it your default
pyenv install 3.13.1
pyenv global 3.13.1
# install a Python virtual environment so we can keep Blinka isolated, then make it active
pyenv virtualenv blinka
pyenv activate blinka
# update pip (it never hurts to make sure you have the latest!)
pip install -u pip
# install the core dependencies and Blinka itself
pip install hidapi
pip install adadfruit-blinka
# When you're done, turn off the virtual environment
pyenv deactivate
Once you've done all that, you should have a working Blinka install on your Mac, isolated in it's own virtual environemnt derived from a custom and managed Python, and ready to go for hardware hacking!
Because we isolated Blinka, we have to turn on our virutal environment when we want to use it:
pyenv activate blinka
and when we're done, we should turn it off:
pyenv deactivate
You could ignore many of the steps listed above. Modern versions of MacOS ship with somewhat recent versions of Python 3 (as of this writing, it's 3.9.6), and does the right thing by default when you install modules with pip, i.e. it assumes --user
. So why do we need Homebrew, pyenv, a custom Python, and the virtual environment?
The simple answer is that the more complex setup will make your life easier in the long run. First, if you're a developer working on MacOS, Homebrew is going to be a good friend (you could also use something like MacPorts, but I switched to Homebrew years ago and I'm not going back). It just makes installing stuff that much easier.
pyenv is a truly wonderful tool for Python devs. Being able to have granular control of your Python install will make coding more stable and also give you the flexibility to adopt the latest and greatest. And you should use Python virtual environments with or without pyenv-virtualenv (see Python's venv for the stock approach to doing this). You want your libraries isolated by use case. Yes, there's some duplication of installed assets, but decoupling your project and use-specific dependencies from your global environment is a key to developer sanity.