Numpy issue on HA core 2024.10.1

Hi all,
I’m on Raspbian GNU/Linux 12 (bookworm) and I have just upgraded HA core from version 2024.9.1 to 2024.10.1. I had a few Python 3.12 dependencies issues (notably with cryptography) that I was able to solve, but there’s one I can’t fix: numpy. Apparently HA requires v1.26.4 of numpy, because it’s not yet ready for v2. Every time I upgrade numpy in my venv to v2.1.2, HA starts without issues, but it reverts the package back to v1.26.4, and the next time I restart HA, I get this error:

Unable to import component: Error importing numpy: you should not try 
to import numpy from its source directory; please exit the numpy source tree, 
and relaunch your python interpreter from there.
ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.12 from "/srv/homeassistant/bin/python3"
  * The NumPy version is: "1.26.4"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: No module named 'numpy.core._multiarray_umath'

I’ve tried several suggestions I found with Google, followed the guide at Troubleshooting — NumPy v2.2.dev0 Manual, but nothing works. I don’t really understand what I’m supposed to do to solve the issue described in the error.

Anyone has any suggestion for me (besides moving to HA OS, which I intend to do in the coming months once I migrate to a Pi 5 !).

Thanks!

I don’t want to jinx it, but it looks like I was able to solve the issue by running this command in my Python venv:

pip3 install numpy==1.26.4 --global-option="-mfloat-abi=hard" --force-reinstall

Same issue here. For some reason I don’t understand, running bin/hass undoes my 1.26.4 and puts my venv right back to 2.1.3. Forcing back to 1.26.4 is pointless like this. What am I doing wrong??

I have the same issue where it automatically puts the venv back to 2.1.3.

edit: running the following command inside my venv seems to prevent restarting hass from reinstalling bumpy 2.1.3

pip freeze > requirements.txt

Hi Guys! Any update about this question ? I’m still running into this problem :frowning:

When I put “pip3 install numpy==1.26.4 --global-option=”-mfloat-abi=hard" --force-reinstall" I receive these warnings:
DEPRECATION: --build-option and --global-option are deprecated. A possible replacement is to use --config-settings. Discussion can be found at Deprecate `--global-option` and `--build-option` · Issue #11859 · pypa/pip · GitHub
WARNING: Implying --no-binary=:all: due to the presence of --build-option / --global-option

If I try install version 2.2 (Last version on pip) and after “pip freeze > requirements.txt” it doesn’t work either.

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)

  1. Navigate to a workspace directory:cd ~
  2. Download NumPy 2.2.2 Source Code:wget https://files.pythonhosted.org/packages/ec/d0/c12ddfd3a02274be06ffc71f3efc6d0e457b0409c4481596881e748cb264/numpy-2.2.2.tar.gz
  3. Extract the Source Code:tar -xzf numpy-2.2.2.tar.gz
  4. Edit the Vendored Meson File: Use a text editor like nano:nano numpy-2.2.2/vendored-meson/meson/mesonbuild/environment.py
  5. 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: the if line should have 4 spaces, and the return 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, then Y, then Enter).
  1. 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 the if, 8 for the return).
  • !! 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 of linux_aarch64) and NumPy linking against incorrect 32-bit libraries (arm-linux-gnueabihf instead of aarch64-linux-gnu).