confluent-kafka-python icon indicating copy to clipboard operation
confluent-kafka-python copied to clipboard

No module found 'attrs'

Open sunny-upstart opened this issue 7 months ago • 1 comments

Seeing issue with attrs dependency when installing version 2.10.0.

Error

    from confluent_kafka.schema_registry import RegisteredSchema
/usr/local/lib/python3.9/site-packages/confluent_kafka/schema_registry/__init__.py:20: in <module>
    from .schema_registry_client import (
/usr/local/lib/python3.9/site-packages/confluent_kafka/schema_registry/schema_registry_client.py:27: in <module>
    from attrs import define as _attrs_define
E   ModuleNotFoundError: No module named 'attrs'

Details

Python Version

3.9.6

requirements.in

I followed the recommendation in the README.md

confluent-kafka[protobuf,schemaregistry] == 2.10.0

I see that the attrs is present in my .venv folder. Image

requirements.txt

This was generated by running pip-compile --no-emit-index-url requirements.in

#
# This file is autogenerated by pip-compile with python 3.9
# To update, run:
#
#    pip-compile --no-emit-index-url requirements.in
#
--trusted-host pypi.org

anyio==4.9.0
    # via httpx
anytree==2.8.0
    # via -r requirements.in
argcomplete==1.12.3
    # via pipx
attrs==21.2.0
    # via confluent-kafka
authlib==1.5.2
    # via confluent-kafka
black==24.3.0
    # via -r requirements.in
build==0.7.0
    # via
    #   -r requirements.in
    #   pip-tools
cachetools==5.5.2
    # via confluent-kafka
certifi==2024.7.4
    # via
    #   httpcore
    #   httpx
    #   requests
cffi==1.17.1
    # via cryptography
cfgv==3.3.1
    # via pre-commit
charset-normalizer==2.0.7
    # via requests
clang-format==13.0.0
    # via -r requirements.in
click==8.0.3
    # via
    #   -r requirements.in
    #   black
    #   pip-tools
    #   userpath
confluent-kafka[protobuf,schemaregistry]==2.10.0
    # via -r requirements.in
coverage==4.5.4
    # via -r requirements.in
cryptography==44.0.2
    # via authlib
datadog==0.44.0
    # via -r requirements.in
dependency-injector==4.40.0
    # via -r requirements.in
distlib==0.3.6
    # via virtualenv
docutils==0.21.2
    # via readme-renderer
exceptiongroup==1.2.2
    # via
    #   anyio
    #   pytest
filelock==3.12.0
    # via virtualenv
gitdb==4.0.9
    # via gitpython
gitpython==3.1.43
    # via -r requirements.in
googleapis-common-protos==1.70.0
    # via confluent-kafka
h11==0.14.0
    # via httpcore
httpcore==1.0.8
    # via httpx
httpx==0.27.2
    # via confluent-kafka
identify==2.5.24
    # via pre-commit
idna==3.7
    # via
    #   anyio
    #   httpx
    #   requests
importlib-metadata==4.8.2
    # via
    #   keyring
    #   twine
inflection==0.5.1
    # via -r requirements.in
iniconfig==1.1.1
    # via pytest
isort==5.11.4
    # via -r requirements.in
jinja2==3.1.4
    # via -r requirements.in
jsonpickle==2.0.0
    # via -r requirements.in
keyring==23.4.0
    # via twine
markdown-it-py==3.0.0
    # via rich
markupsafe==2.0.1
    # via jinja2
mdurl==0.1.2
    # via markdown-it-py
mypy==0.942
    # via -r requirements.in
mypy-extensions==0.4.3
    # via
    #   black
    #   mypy
mypy-protobuf==3.2.0
    # via -r requirements.in
nh3==0.2.21
    # via readme-renderer
nodeenv==1.8.0
    # via pre-commit
nullsafe==0.2.1
    # via -r requirements.in
packaging==23.1
    # via
    #   black
    #   build
    #   pipx
    #   pytest
    #   twine
pathspec==0.9.0
    # via black
pep517==0.12.0
    # via build
pip-tools==6.8.0
    # via -r requirements.in
pipx==0.16.4
    # via -r requirements.in
pkginfo==1.12.0
    # via
    #   -r requirements.in
    #   twine
platformdirs==3.5.1
    # via
    #   black
    #   virtualenv
pluggy==1.5.0
    # via pytest
pre-commit==3.3.1
    # via -r requirements.in
protobuf==4.21.9
    # via
    #   -r requirements.in
    #   confluent-kafka
    #   googleapis-common-protos
    #   mypy-protobuf
pycparser==2.22
    # via cffi
pydantic==1.10.13
    # via -r requirements.in
pygments==2.15.0
    # via
    #   readme-renderer
    #   rich
pytest==8.3.5
    # via
    #   -r requirements.in
    #   pytest-mock
    #   pytest-snapshot
pytest-mock==3.6.1
    # via -r requirements.in
pytest-snapshot==0.7.0
    # via -r requirements.in
pyyaml==6.0
    # via
    #   -r requirements.in
    #   pre-commit
readme-renderer==44.0
    # via twine
requests==2.32.2
    # via
    #   -r requirements.in
    #   datadog
    #   requests-toolbelt
    #   responses
    #   twine
requests-toolbelt==0.9.1
    # via twine
responses==0.15.0
    # via -r requirements.in
rfc3986==1.5.0
    # via twine
rich==13.9.4
    # via twine
six==1.16.0
    # via
    #   anytree
    #   dependency-injector
    #   responses
smmap==5.0.0
    # via gitdb
sniffio==1.3.1
    # via
    #   anyio
    #   httpx
tomli==1.2.2
    # via
    #   black
    #   build
    #   mypy
    #   pep517
    #   pytest
twine==6.0.1
    # via -r requirements.in
types-protobuf==3.19.15
    # via mypy-protobuf
types-pyyaml==6.0.11
    # via -r requirements.in
types-requests==2.28.5
    # via -r requirements.in
types-urllib3==1.26.17
    # via types-requests
typing-extensions==4.6.3
    # via
    #   anyio
    #   black
    #   mypy
    #   pydantic
    #   rich
urllib3==1.26.19
    # via
    #   requests
    #   responses
    #   twine
userpath==1.7.0
    # via pipx
virtualenv==20.23.0
    # via pre-commit
wheel==0.38.0
    # via pip-tools
zipp==3.19.1
    # via importlib-metadata

# The following packages are considered to be unsafe in a requirements file:
# pip
# setuptools

Any help would be appreciated to resolve this. Let me know if you need additional information. Thanks!

sunny-upstart avatar Apr 18 '25 04:04 sunny-upstart

Is there a workaround for this? Currently blocked.

rm-rf-etc avatar Jun 06 '25 18:06 rm-rf-etc

Here is my attemp to to address the issue by PR #2007 which adds version constraints to the schemaregistry dependencies.

I faced the same issue recently. The issue might be related to how pip handles the installation of optional dependencies. When using extras like [protobuf,schemaregistry], sometimes the dependency resolution doesn't properly install all required packages, especially when they're specified without version constraints.

Try to install the deps manually as workarround (worked out for me at least):

pip install attrs cachetools httpx>=0.26 authlib>=1.0.0
pip install confluent-kafka[protobuf,schemaregistry]==2.10.0

aywengo avatar Jul 05 '25 11:07 aywengo