Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [Docker] [Modbus] ImportError: cannot import name 'Defaults' from 'pymodbus.constants' #1158

Closed
elgutierrez opened this issue Aug 5, 2023 · 0 comments · Fixed by #1160
Assignees
Labels

Comments

@elgutierrez
Copy link

Describe the bug
I'm using the latest docker image (3.3) on a Raspberry Pi 4. When starting the container using a modbus connector, I'm getting this error:

ImportError: cannot import name 'Defaults' from 'pymodbus.constants'

I found this post on a forum complaining about the same issue, and the only answer there suggested a workaround that worked for me. Apparently, the newer version of pymodbus isn't exporting the Defaults class, so I downgraded pymodbus to 3.4.0 version

docker exec -it [ID] bash

# inside the container
$ pip install 'pymodbus<3.4.0' --force-reinstall

This solved my issue for now but I'd need to manually do it to many of my gateways so it's not really scalable. That should be fixed in the docker image itself

Connector name (If bug in the some connector):
Modbus Connector

Error traceback

""2023-08-05 17:19:17" - |DEBUG| - [tb_loader.py] - tb_loader - import_module - 59 - ModuleSpec(name='GrpcModbusConnector', loader=<_frozen_importlib_external.SourceFileLoader object at 0xf58ab160>, origin='/thingsboard_gateway/grpc_connectors/modbus/modbus_connector.py')"
""2023-08-05 17:19:17" - |ERROR| - [tb_loader.py] - tb_loader - import_module - 72 - cannot import name 'Defaults' from 'pymodbus.constants' (/root/.local/lib/python3.10/site-packages/pymodbus/constants.py)"
Traceback (most recent call last):
  File "/thingsboard_gateway/tb_utility/tb_loader.py", line 65, in import_module
    module_spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/thingsboard_gateway/grpc_connectors/modbus/modbus_connector.py", line 31, in <module>
    from thingsboard_gateway.grpc_connectors.modbus.slave import Slave
  File "/thingsboard_gateway/grpc_connectors/modbus/slave.py", line 18, in <module>
    from pymodbus.constants import Defaults
ImportError: cannot import name 'Defaults' from 'pymodbus.constants' (/root/.local/lib/python3.10/site-packages/pymodbus/constants.py)

Versions:

  • OS: Linux Debian 11.7; Docker 24.0.5
  • Thingsboard IoT Gateway version: 3.3
  • Python version: 3.10.12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants