Installed a new version of Raspberry Pi OS (bookworm) on a Zero W and then tried to install unicornhat library by executing the install script:
curl https://get.pimoroni.com/unicornhat | bash
Got error:
Installing Unicorn HAT/pHAT library for Python 3...
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.
If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.
For more information visit http://rptl.io/venv
note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
Python 3 library install failed!
I’m not very familiar with this python virtual env stuff, so I googled a bit and then I tried creating a virtual env and activated it and then tried installing again. The install script uses sudo pip so it wasn’t working correctly. Also tried installing manually with pip, and while the install worked, but when trying to use import unicornhat
in code still got errors like ws2811_init failed
etc. Then cloned the repo and went to library dir and executed setup.py install for both UnicornHat and legacy/rpi-ws281x but still same result.
Finally googled more about the virtual env and how to disable it. Executed this:
sudo python3 -m pip config set global.break-system-packages true
And after that the install script worked, and my Unicorn pHAT is working again!
There was still an error at the end of the install script, but that was related to the audio setup it does (by loading another script from https://get.pimoroni.com/audio as seems like that script doesn’t yet support bookworm either). Don’t know what that script is supposed to do, but I guess it doesn’t matter on Pi zero as it doesn’t have audio anyway…
Not sure if the Unicorn pHAT and the unicornhat library is supposed to be supported anymore since the repo is archived and they don’t sell it anymore, but thought to post this here anyway since it might be useful to someone else.
Also, if anyone has any pointers to how the python virtual env stuff is supposed to be used on Raspberry Pis running these Pimoroni libraries, feel free to comment here or add relevant links.