Installing the Weather HAT Python library fails

I have read the page learn.pimoroni.com/article/getting-started-with-weather-hat and tried to follow instructions. When I type sudo ./install.sh
I get message
Script should not be run as root. Try ‘./install.sh’
When I type ./install.sh I get messages
weatherhat Python Library: Installer

Checking Dependencies. Please wait…
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 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.
Installing stable library from pypi.

Installing for Python 3.11.2…

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 //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.
Setting up i2c and SPI… Backing up /boot/config.txt to /boot/config.preinstall-weatherhat-2023-10-17-16-40-04.txt

/usr/bin/raspi-config: 291: cannot create /boot/firmware/config.txt.bak: Permission denied
mv: cannot stat ‘/boot/firmware/config.txt.bak’: No such file or directory
sed: couldn’t open temporary file /etc/modprobe.d/sedbZd6sx: Permission denied
** Must be run as root - try ‘sudo dtparam …’*
/usr/bin/raspi-config: 291: cannot create /boot/firmware/config.txt.bak: Permission denied
mv: cannot stat ‘/boot/firmware/config.txt.bak’: No such file or directory
sed: couldn’t open temporary file /etc/modprobe.d/sedg0irFC: Permission denied
sed: couldn’t open temporary file /etc/sedFYvEPg: Permission denied
** Must be run as root - try ‘sudo dtparam …’*
Would you like to copy examples to /home/pi/Pimoroni/weatherhat? [y/N]

Would you like to generate documentation? [y/N] n

All done!
If this is your first time installing you should reboot for hardware changes to take effect.

Find uninstall steps in /home/pi/Pimoroni/weatherhat/uninstall.sh

What should I do? I’m beginner with Raspberry Pi and Python (and English too). My Raspberry Pi is Raspberry Pi Model B Plus Rev 1.2 with Raspbian GNU/Linux 12 (bookworm)

It’s a result of changes made in the new Desktop 12 (Bookworm) release.
Raspberry Pi Documentation - Raspberry Pi OS
I’m in a similar situation.
St7789 install error with Bookworm? - Support - Pimoroni Buccaneers

In the latest version of Raspberry Pi OS (Bookworm) software packages need to be installed into a ‘virtual environment’ which is more secure, but requires significantly more setup on the part of the user.

This PR contains some details about what’s changed with package installation with Bookworm, along with some plans we have for things we can might be able to do to make setup easier for folks: Raspberry Pi OS Bookworm + Pep 668 by Gadgetoid · Pull Request #13 · pimoroni/boilerplate-python · GitHub

It will likely take us a while to get our old installers working (or new ones setup), so you’re probably best using the legacy version of Raspberry Pi OS for now if you want the installer to just work :) You can flash it with Raspberry Pi Imager - it’s under Raspberry Pi OS (other) > Raspberry Pi OS (Legacy).

Yes, Bullseye is still a good choice (and btw uses the same kernel anyhow).

As a side note: the virtual environment is not so much targeted at security, but it prevents mixing (potentially slightly) incompatible python code. E.g. python of PiOS might provide a requests package and then an installer does a “sudo pip3 install requests” and then you run into strange errors which are very hard to track down because you don’t know which requests-code is actually executed.

@Hel: when you update your installers, try to make sure to install system packages instead of pip packages when they are available and do the job. This is not always the case and sometimes pip provides better/updated versions, but at least try to use system-packages first. System-packages are also covered by security-updates for the distribution, which is also a good argument for them.

That’s a good point, having the wrong version of a package installed can ruin your day.

I’m not a software dev, but you could drop a comment on @Gadgetoid’s PR that I linked above if you have a view on how the new installers should be implemented.

My setup was a Pi 400 with a trackball, rv3028 and st7789 LCD breakouts. I went legacy OS for now. No problems going that route. Just a for your info post. ;)