Hi Home Assistant team and community,
I’m encountering a persistent ImportError: cannot import name ‘CommunityData’ from ‘pysnmp.hlapi’ when trying to use a custom component that relies on the pysnmp library on my Home Assistant OS installation.
Environment:
Home Assistant OS (latest stable version - please specify your version here: ...)
Running Home Assistant Core in Docker (container ID: ... or name homeassistant)
Python version inside the container: 3.13 (as per python3 -c "import sys; print(sys.version_info)" inside the container)
Custom component: snmp_attomat (but the issue seems to be with pysnmp itself)
Problem Description:
A custom component I’m trying to use requires the pysnmp library. While I can install pysnmp inside the Home Assistant Core container using pip, I consistently get the ImportError: cannot import name ‘CommunityData’ from ‘pysnmp.hlapi’ when the component tries to use it.
Steps I have taken to troubleshoot:
Verified pysnmp installation: Inside the container, pip show pysnmp indicates the library is installed (currently version 7.1.17, also tried 6.2.6). It's located in /usr/local/lib/python3.13/site-packages.
Checked Python path: The Python path inside the container includes /usr/local/lib/python3.13/site-packages.
Uninstalled and reinstalled pysnmp: Tried multiple times with pip uninstall pysnmp and pip install --no-cache-dir pysnmp (and specific versions).
Checked pysnmp/hlapi/__init__.py: Initially, this file was missing. After forcing reinstall, the file now exists (it was empty at one point, but after the latest forced reinstall, it's present - please specify if it's empty for you: ...).
Tried importing directly in the container's Python interpreter:
Bash
python3 -c "from pysnmp.hlapi import CommunityData; print(CommunityData)"
This command still results in the ImportError (with the path to __init__.py now included in the error message).
Checked other files in pysnmp/hlapi: The directory contains __pycache__, asyncio.py, transport.py, v1arch, v3arch, and varbinds.py.
Forced reinstall of pysnmp: Used pip install --no-cache-dir --force-reinstall pysnmp.
Current Status:
The pysnmp library seems to be installed, and the init.py file in pysnmp/hlapi now exists (though I’m not sure of its correct content - please specify if you checked its content using cat /usr/local/lib/python3.13/site-packages/pysnmp/hlapi/init.py and what it contains). However, the ImportError persists.
I suspect there might be an issue with how pysnmp is being installed or how Home Assistant Core is accessing it within the container environment on Home Assistant OS.
Any help or insights into resolving this import error would be greatly appreciated.
Thank you!
Before submitting, please fill in the following details in the issue:
Your Home Assistant OS version.
The container ID of your Home Assistant Core container (if you know it).
The content of the /usr/local/lib/python3.13/site-packages/pysnmp/hlapi/__init__.py file (if you managed to check it).