I finally managed to install numpy 2.2.2 using the following steps with help from this post and Gemini.
Workaround Steps: This involves downloading the NumPy source, manually patching the vendored Meson file, and then installing the patched source.
(Run these commands as the user who manages your Home Assistant virtual environment, e.g., homeassistant
or pi
)
- Navigate to a workspace directory:
cd ~
- Download NumPy 2.2.2 Source Code:
wget https://files.pythonhosted.org/packages/ec/d0/c12ddfd3a02274be06ffc71f3efc6d0e457b0409c4481596881e748cb264/numpy-2.2.2.tar.gz
- Extract the Source Code:
tar -xzf numpy-2.2.2.tar.gz
- Edit the Vendored Meson File: Use a text editor like nano:
nano numpy-2.2.2/vendored-meson/meson/mesonbuild/environment.py
- Apply the Patch:
- Inside the editor, find the function definition line (around line 960-970):
def need_exe_wrapper(self, for_machine: MachineChoice = MachineChoice.HOST):
- Immediately after this
def
line, insert the following two lines. Crucially, ensure correct indentation: theif
line should have 4 spaces, and thereturn
line should have 8 spaces.if not self.is_cross_build(): return False
- The beginning of the function should now look like this:
def need_exe_wrapper(self, for_machine: MachineChoice = MachineChoice.HOST):
# ---- Start of Inserted Patch ----
if not self.is_cross_build():
return False
# ---- End of Inserted Patch ----
# Original code continues below
value = self.properties[for_machine].get('needs_exe_wrapper', None)`
# ... rest of function
- Save the file and exit
nano
(Ctrl+X
, thenY
, thenEnter
).
- Install the Patched NumPy:
-
Activate your Home Assistant virtual environment:
source /srv/homeassistant/bin/activate
-
Make sure you are in the directory containing the
numpy-2.2.2
folder (e.g.,cd ~
). -
Run the installation:
pip install ./numpy-2.2.2
Important Notes & Warnings:
- Workaround, Not a Fix: This manually patches the NumPy source for this specific installation. If you update/reinstall NumPy or recreate your virtual environment, you’ll need to repeat the patch.
- Indentation Matters: Python errors (
TabError
) will occur if the indentation of the added lines is incorrect. Use spaces, not tabs (4 for theif
, 8 for thereturn
). - !! Potential for Incorrect Final Package !!: Even after this patch allows the build to complete, the underlying platform detection issue within Meson might persist. In testing, this resulted in the final wheel being incorrectly tagged (
linux_armv7l
instead oflinux_aarch64
) and NumPy linking against incorrect 32-bit libraries (arm-linux-gnueabihf
instead ofaarch64-linux-gnu
).