Context
Home Assistant currently has compatibility issues when attempting to install the netCDF4
package. This package is essential for working with netCDF data files, which are widely used in scientific and meteorological applications.
Error Message
When adding an integration that requires the netCDF4
package, an error is logged in the Home Assistant log file. Regarding the full error message, please refer to the Attachment section below.
Workaround
To install netCDF4
, the following steps were taken in the Home Assistant Docker container:
-
Access the Home Assistant container:
docker exec -it homeassistant /bin/bash
-
Install required packages:
apk update apk add --no-cache netcdf-dev hdf5 hdf5-dev gcc g++ python3-dev musl-dev libffi-dev
-
Set environment variables:
export CFLAGS="-I/usr/include" export LDFLAGS="-L/usr/lib" export CPPFLAGS="-I/usr/include" export HDF5_DIR="/usr" export NETCDF4_DIR="/usr"
-
Install
wheel
andCython
:pip install wheel cython
-
Install
netCDF4
andcftime
:pip install netCDF4 cftime --no-build-isolation
While this workaround enables the installation of netCDF4
, it is cumbersome and not user-friendly. Additionally, such a workaround is not fully supported and may bear stability risks, potentially affecting the overall reliability of the Home Assistant installation.
Proposal
Improve Home Assistant’s compatibility with the netCDF4
package by including the necessary build dependencies and environment configurations in the Home Assistant Docker image. This will enable users to install netCDF4
seamlessly and utilize its capabilities within Home Assistant.
Use Cases
- Weather and Climate Data Integration: Facilitates the integration of weather and climate data from netCDF files into Home Assistant.
- Environmental Monitoring: Supports automating the processing and visualization of netCDF data for environmental monitoring applications.
Benefits
- Enhanced Functionality: Enables users to easily install and use the
netCDF4
package, expanding the range of data sources and applications available within Home Assistant. - User Convenience: Simplifies the process for users, eliminating the need for manual workarounds and custom Docker images.
- Stability: Reduces the potential risks associated with unsupported manual workarounds, enhancing the overall stability of Home Assistant installations.
Conclusion
Enhancing Home Assistant’s compatibility with the netCDF4
package will greatly benefit users who rely on scientific and meteorological data, making Home Assistant a more powerful tool for data integration and automation.
Attachment: Full Error Message
[homeassistant.util.package] Unable to install package dwd_global_radiation==1.1.0rc4: error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [40 lines of output]
Package hdf5 was not found in the pkg-config search path.
Perhaps you should add the directory containing `hdf5.pc'
to the PKG_CONFIG_PATH environment variable
Package 'hdf5', required by 'virtual:world', not found
reading from setup.cfg...
HDF5_DIR environment variable not set, checking some standard locations ..
checking /root/include ...
hdf5 headers not found in /root/include
checking /usr/local/include ...
hdf5 headers not found in /usr/local/include
checking /sw/include ...
hdf5 headers not found in /sw/include
checking /opt/include ...
hdf5 headers not found in /opt/include
checking /opt/local/include ...
hdf5 headers not found in /opt/local/include
checking /opt/homebrew/include ...
hdf5 headers not found in /opt/homebrew/include
checking /usr/include ...
hdf5 headers not found in /usr/include
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
main()
File "/usr/local/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
return hook(config_settings)
^^^^^^^^^^^^^^^^^^^^^
File "/tmp/pip-build-env-bgz_6rql/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 325, in get_requires_for_build_wheel
return self._get_build_requires(config_settings, requirements=['wheel'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/pip-build-env-bgz_6rql/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 295, in _get_build_requires
self.run_setup()
File "/tmp/pip-build-env-bgz_6rql/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 311, in run_setup
exec(code, locals())
File "<string>", line 457, in <module>
File "<string>", line 398, in _populate_hdf5_info
ValueError: did not find HDF5 headers
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.