A while ago I started using the SolarEdge Modbus Python library to obtain statistics from my SolarEdge inverter. This library uses the uses the pymodbus library in the background, to establish a TCP Modbus connection to the inverter.
This has worked fine for a very long time. Until today. Today I upgraded the relevant machine from Debian 11 (Bullseye) to 12 (Bookworm) - yes, I know, still one version away from stable again.
Unfortunately I noticed this several hours later, when I had a look at my SolarEdge Grafana Dashboard:

As it turns out, the service used to run the Python script failed since the distribution upgrade. Manually running the Python script confirmed the error:
ck@debian:~$ /home/ck/solaredge_modbus/modified_influxdb.py --interval 60 --influx_host localhost --influx_db solaredge solaredgeinverter 1502
Traceback (most recent call last):
File "/home/ck/solaredge_modbus/modified_influxdb.py", line 10, in <module>
import solaredge_modbus
ModuleNotFoundError: No module named 'solaredge_modbus'
With the Debian upgrade, the Python version was upgraded from 3.9 to 3.11. Hence the previously installed Python modules (using pip3) were not installed.
Let's install the solaredge-modbus library again:
ck@debian:~$ pip3 install solaredge-modbus --break-system-packages
[...]
Installing collected packages: pyserial, pyserial-asyncio, pymodbus, solaredge-modbus
Successfully installed pymodbus-3.11.4 pyserial-3.5 pyserial-asyncio-0.6 solaredge-modbus-0.8.0
The module "solaredge_modbus" could now be loaded, but unfortunately another error showed up:
ck@debian:~$ /home/ck/solaredge_modbus/modified_influxdb.py
--interval 60 --influx_host localhost --influx_db solaredge
solaredgeinverter 1502
Traceback (most recent call last):
File "/home/ck/solaredge_modbus/modified_influxdb.py", line 10, in <module>
import solaredge_modbus
File "/home/ck/.local/lib/python3.11/site-packages/solaredge_modbus/__init__.py", line 4, in <module>
from pymodbus.constants import Endian
ImportError: cannot import name 'Endian' from 'pymodbus.constants' (/home/ck/.local/lib/python3.11/site-packages/pymodbus/constants.py)
This time there's an issue with the pymodbus library, which was installed by pip3 as a dependency.
After a bit of research, I stumbled across an open issue which mentions compatibility issues of the solaredge_modbus module with newer pymodbus versions:
There are some breaking updates on pymodbus that require updates to their users, including solaredge_modbus.
The requirements for this repository are pymodbus ~= 3.5.0 (see setup.cfg).
Herbi3 made a fork which states pymodbus >= 3.5.0 (see https://github.com/herbi3/solaredge_modbus), but it fails with pymodbus >= 3.9.0 .
pip3 installed a recent version (3.11.4) of pymodbus:
ck@icinga2:~$ ls -la .local/lib/python3.11/site-packages/
total 32
drwxr-xr-x 11 ck ck 4096 Jan 11 14:39 pymodbus
drwxr-xr-x 3 ck ck 4096 Jan 11 14:39 pymodbus-3.11.4.dist-info
drwxr-xr-x 2 ck ck 4096 Jan 11 14:39 pyserial-3.5.dist-info
drwxr-xr-x 2 ck ck 4096 Jan 11 14:39 pyserial_asyncio-0.6.dist-info
drwxr-xr-x 6 ck ck 4096 Jan 11 14:39 serial
drwxr-xr-x 3 ck ck 4096 Jan 11 14:39 serial_asyncio
drwxr-xr-x 3 ck ck 4096 Jan 11 14:39 solaredge_modbus
drwxr-xr-x 2 ck ck 4096 Jan 11 14:39 solaredge_modbus-0.8.0.dist-info
This information turned out to be crucial; the script worked before. What version of pymodbus was used before?
ck@debian:~$ ls -la .local/lib/python3.9/site-packages/
total 64
drwxr-xr-x 6 ck ck 4096 Apr 29 2024 dateutil
drwxr-xr-x 5 ck ck 4096 Apr 29 2024 influxdb
drwxr-xr-x 2 ck ck 4096 Apr 29 2024 influxdb-5.3.2.dist-info
drwxr-xr-x 3 ck ck 4096 Apr 29 2024 msgpack
drwxr-xr-x 2 ck ck 4096 Apr 29 2024 msgpack-1.0.8.dist-info
drwxr-xr-x 9 ck ck 4096 Apr 29 2024 pymodbus
drwxr-xr-x 2 ck ck 4096 Apr 29 2024 pymodbus-3.6.8.dist-info
drwxr-xr-x 2 ck ck 4096 Apr 29 2024 pyserial-3.5.dist-info
drwxr-xr-x 2 ck ck 4096 Apr 29 2024 pyserial_asyncio-0.6.dist-info
drwxr-xr-x 2 ck ck 4096 Apr 29 2024 python_dateutil-2.9.0.post0.dist-info
drwxr-xr-x 4 ck ck 4096 Apr 29 2024 pytz
drwxr-xr-x 2 ck ck 4096 Apr 29 2024 pytz-2024.1.dist-info
drwxr-xr-x 6 ck ck 4096 Apr 29 2024 serial
drwxr-xr-x 3 ck ck 4096 Apr 29 2024 serial_asyncio
drwxr-xr-x 3 ck ck 4096 Apr 29 2024 solaredge_modbus
drwxr-xr-x 2 ck ck 4096 Apr 29 2024 solaredge_modbus-0.8.0.dist-info
As it turns out, the script was working fine before under Debian 11 with Python 3.9 and pymodbus 3.6.8.
Will it work if I use the same site-packages from 3.9 in 3.11?
ck@debian:~$ rm -rf .local/lib/python3.11/site-packages/pymodbus*
ck@debian:~$ cp -Rp .local/lib/python3.9/site-packages/pymodbus* .local/lib/python3.11/site-packages/
ck@debian:~$ /home/ck/solaredge_modbus/modified_influxdb.py
--interval 60 --influx_host localhost --influx_db solaredge
solaredgeinverter 1502
Startup complete
It works again, hurray!
As an alternative to the manual package copy, the pymodbus pip3 package can be downgraded to the same version:
ck@debian:~$ pip3 install pymodbus==3.6.8 --break-system-packages
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pymodbus==3.6.8 in ./.local/lib/python3.11/site-packages (3.6.8)
No comments yet.
AWS Android Ansible Apache Apple Atlassian BSD Backup Bash Bluecoat CMS Chef Cloud Coding Consul Containers CouchDB DB DNS Databases Docker ELK Elasticsearch Filebeat FreeBSD Galera Git GlusterFS Grafana Graphics HAProxy HTML Hacks Hardware Icinga Influx Internet Java KVM Kibana Kodi Kubernetes LVM LXC Linux Logstash Mac Macintosh Mail MariaDB Minio MongoDB Monitoring Multimedia MySQL NFS Nagios Network Nginx OSSEC OTRS Observability Office OpenSearch PHP Perl Personal PostgreSQL PowerDNS Proxmox Proxy Python Rancher Rant Redis Roundcube SSL Samba Seafile Security Shell SmartOS Solaris Surveillance Systemd TLS Tomcat Ubuntu Unix VMware Varnish Virtualization Windows Wireless Wordpress Wyse ZFS Zoneminder