Search code examples
pythonpython-3.xconfluent-platformconfluent-kafka-python

Cannot import Producer from confluent_kafka


I'm using conda environment with python 3.9 and confluent_kafka library (installation by pip install confluent-kafka). I have also installed librdkafka. From pycharm I cannot import:

from confluent_kafka import Producer

I receive this errors:

Traceback (most recent call last):
  File "D:/Python/Projects/Kafka/main.py", line 1, in <module>
    from confluent_kafka import Producer
  File "C:\Users\kmode\anaconda3\envs\dataScience\lib\site-packages\confluent_kafka\__init__.py", line 40, in <module>
    from .deserializing_consumer import DeserializingConsumer
  File "C:\Users\kmode\anaconda3\envs\dataScience\lib\site-packages\confluent_kafka\deserializing_consumer.py", line 19, in <module>
    from confluent_kafka.cimpl import Consumer as _ConsumerImpl
ImportError: DLL load failed while importing cimpl: 

Can you help to solve this problem?


Solution

  • After reinstalations of anaconda and removing python 3.9 I fixed the issued by using python 3.7. in anaconda environment. As stated here the reason is to have version 3.8 and higher, but I don't know how to resolve it exactly on python 3.8 and above.

    If anyone comes across this issue in Python > 3.8 with Windows, dll's are only loaded from trusted locations https://docs.python.org/3/whatsnew/3.8.html#ctypes This can be fixed by adding the dll path using os.add_dll_directory("PATH_TO_DLL")