Search code examples
pythonapache-kafkakafka-python

ModuleNotFoundError: No module named 'kafka'


I have downloaded Kafka and installed kafka-python library using "pip install kafka-python" and "conda install -c conda-forge kafka-python".

I am able to run "from kafka import KafkaProducer" inside a python shell on the terminal. But the same line shows "ModuleNotFoundError: No module named 'kafka'" on Jupyter Notebook.

I would be thankful for any help on how to resolve this.

enter image description here


Solution

  • Reinstall Jupyter from the Homebrew's Python (Python 3.11), rather than run it from your system's python (Python 3.9, which you would have had to use sudo pip install, which is wrong)

    You should not need both conda and pip to manage packages.

    Then, install packages outside of Jupyter

    e.g.

    python3 -m venv venv
    source ./venv/bin/activate
    python3 -m pip install jupyterlab kafka-python
    jupyter-lab