简体   繁体   中英

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?

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")

Answer already existing


I saw an answer similar to yours (not a duplicate at all, but it solves your problem).
How to resolve "ImportError: DLL load failed:" on Python?


They suggested to uninstall and then reinstall python, and if I understood well it worked.


Somebody else installed Anaconda instead, and it worked too.

对于那些在 Python>=3.8 中使用 Anaconda 的人,请设置您的环境变量。

set CONDA_DLL_SEARCH_MODIFICATION_ENABLE=1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM