dpkp / kafka-python

Python client for Apache Kafka
http://kafka-python.readthedocs.io/
Apache License 2.0
5.62k stars 1.41k forks source link

Cannot import name 'KafkaProducer' from 'kafka' #2041

Open Xiezhibin opened 4 years ago

Xiezhibin commented 4 years ago

I run the code "from kafka import KafkaProducer" in my jupyter-notebook, it report an error that "Cannot import name 'KafkaProducer' from 'kafka' (unknown location)"。

But the code work well in terminal。

Python: 3.7.7 in anaconda virtual environment

kafka-python:2.0.1

mamilov commented 4 years ago

Getting the same error, could you fix it? Edit: nvm, was able to fix it by reinstalling with pipenv

tvoinarovskyi commented 4 years ago

Please install the package kafka-python, not kafka. This behaviour may happen if you had 2 packages installed at some time. If you end up with such a situation, please reinstall kafka-python using:

pip uninstall kafka
pip uninstall kafka-python
pip install kafka-python

You have to uninstall it completely first because just installing a new version will not reset the loader properly. Sorry for the trouble.

markysie commented 1 year ago

thanks a lot have a great day

kirikike commented 5 months ago

I have installed kafka-python and not kafka. But it stills giving me the error: ImportError: cannot import name 'KafkaProducer' from 'kafka' (unknown location) I've cheked that all the files from the package kafka-python are correct, I've uninstalled and installed it again. Nothing works.

Can anyone help me please?

25Parul commented 4 months ago

Try ReTyping the same command from kafka import KafkaProducer

omgsian commented 1 month ago

Try ReTyping the same command from kafka import KafkaProducer

That works for me. Thanks