Weather hat software failing on Raspberry pi 5?

When I run this it fails: git clone GitHub - pimoroni/weatherhat-python
cd weatherhat-python
sudo ./install.sh

The error is i5-larry@raspberrypi:~/weatherhat-python $ ./install.sh
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.

1 Like

Hi Phil.

Hope you’re well.
What is inside install.sh?
The Pi5 Architectures slightly different from the 4, so the installer may not be pi5 compatible.
Are you comfortable jumping inside install.sh and looking for any false HALs or hard coded ROM addresses that may no longer exist on pi5?

Hi Pixmusix, not familiar with the false HAL’s etc…

was reading on the Support - Pimoroni Forum, a few ppl reporting the same…

Weather hat software failing on Raspberry pi 5 - Support - Pimoroni Buccaneers

Cheers in advance

Phil

Totally fine. Lets go through it together.
Here is the code we want to inspect.

The first thing I’d do here is check the error message for something to search.
This line below is interesting, because it’s probably generated by the code. So let’s search for that.

Checking Dependencies. Please wait…

Here it is, looks like at minimum we made it to line 139.

inform "Checking Dependencies. Please wait..."

pip_pkg_install toml

CONFIG_VARS=`$PYTHON - <<EOF
import toml
config = toml.load("pyproject.toml")
p = dict(config['pimoroni'])
# Convert list config entries into bash arrays
for k, v in p.items():
    v = "'\n\t'".join(v)
    p[k] = f"('{v}')"
print("""
APT_PACKAGES={apt_packages}
SETUP_CMDS={commands}
CONFIG_TXT={configtxt}
""".format(**p))
EOF`

Looks like we didn’t make it past this CONF_VARS python file.
That’s trying to import a toml which is essentially a hardware abstraction config package.
That’s the kind thing we want to check up on. Let’s find that.

So the first thing I notice is that the toml says we require project 3.7.
That’s interesting and worth checking.
The second thing to notice is that this project uses Hatchling which is a buildchain.
I happen to know Hatchling doesn’t like opperating under sudo.
That actually lines up with something else I noticed

    if [ $(id -u) -eq 0 ]; then
        printf "Script should not be run as root. Try './install.sh'\n"
        exit 1
    fi

So two thing I’d check

  1. what version of python and I running.
  2. trying running as install.sh as a user, not root.

Let me know how that goes.
Pix :heavy_heart_exclamation:

Hi Pixmusix,

  1. Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux
  2. ran as ./install.sh not as root.

Phil

Hmm.

Ok the next thing I would want to see is this python config file actually looks like.
Try adding this line to your install.sh file and see if you can get an output.
I’d put it on line 162 just before the evaluation.

echo CONFIG_VARS

Does it all look good?
We want it to have a format similar to apt install python3-xyz

that didn’t display any output

if [ $? -ne 0 ]; then

warning “Error parsing configuration…\n”

exit 1

fi

echo CONFIG_VARS

eval $CONFIG_VARS

RESOURCES_DIR=$RESOURCES_TOP_DIR/$LIBRARY_NAME

UNINSTALLER=$RESOURCES_DIR/uninstall.sh

there is some further output being generated

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 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.
Setting up i2c and SPI… Backing up /boot/config.txt to /boot/config.preinstall-weatherhat-2024-05-03-16-40-01.txt

/usr/bin/raspi-config: 319: 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/sedv3hM1f: Permission denied

  • Must be run as root - try ‘sudo dtparam …’
    /usr/bin/raspi-config: 319: 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/sedTO0HcE: Permission denied
    sed: couldn’t open temporary file /etc/sedCr1jgV: Permission denied
  • Must be run as root - try ‘sudo dtparam …’
    Would you like to copy examples to /home/phil.kern/Pimoroni/weatherhat? [y/N] n

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

Hey Phil,

With the Pi 5 and Bookworm OS, something that has caught everyone off guard is that we need to use virtual environments when installing packages system-wide with pip, and this may be giving you an error.
We have a fix for it, but this is in thonny. I haven’t ever set up a virtual environment outside of Thonny, but here is an Adafruit tutorial on it.

Its suuuuper annoying and the folks at Raspberry Pi Foundation express their dislike of it, its out of their control.

Hope this helps

-Jaryd

1 Like

AHH!! That’s the problem!
@Jaryd seems to have a solution.

will scope it…
will update you…

Phil

1 Like

Hey Jaryd,
I will try the thony version as I wasn’t having any luck with the Adafruit version.
will update you.

Cheers in advance

Phil

2 Likes