I am using the confluent-kafka Python client in my project. I’m trying to create a Docker image with this client.
I am facing the following error:-
#11 8.015 [pipenv.exceptions.InstallError]: In file included from /tmp/pip-install-so_whhii/confluent-kafka_9d9553bf46cf489bb25fcb2ac7698747/src/confluent_kafka/src/Admin.c:17:
#11 8.015 [pipenv.exceptions.InstallError]: /tmp/pip-install-so_whhii/confluent-kafka_9d9553bf46cf489bb25fcb2ac7698747/src/confluent_kafka/src/confluent_kafka.h:23:10: fatal error: librdkafka/rdkafka.h: No such file or directory
#11 8.015 [pipenv.exceptions.InstallError]: 23 | #include <librdkafka/rdkafka.h>
#11 8.015 [pipenv.exceptions.InstallError]: | ^~~~~~~~~~~~~~~~~~~~~~
#11 8.015 [pipenv.exceptions.InstallError]: compilation terminated.
#11 8.015 [pipenv.exceptions.InstallError]: error: command '/usr/bin/gcc' failed with exit code 1
#11 8.016 [pipenv.exceptions.InstallError]: [end of output]
Based on my search it is related to Apple M1 build for librdkafka.
7
Answers
Prebuilt binary wheels of
confluent-kafka-python
for your Apple M1 seems to not exist.Thus, in order to install the package,
pip
tries to build it itself from source. Butlibrdkafka
looks like to not be installed as perlibrdkafka/rdkafka.h: No such file or directory
error you got.You can find specific instructions to install from source for different platforms here.
The Confluent engineers are obviously very focused on their paying customers, and many, many months after the release of Python 3.10, they still haven’t released 3.10 wheels that include the binaries for the package.
https://github.com/confluentinc/confluent-kafka-python/issues/1219
You have two choices. 1, run Python 3.9; 2, install
librdkafka-dev
via apt before installingconfluent-kafka
(for a debian base image).The issue is the same with Apple M1 – i.e, there are no pre-built wheels for the platform containing the binaries, but it is much easier to fix (by installing
librdkafka-dev
) if you are trying to build aamd64
Linux image.Please refer to this Github issue. The problem with M1 is that Homebrew is installed in a different location and so these variables need to be added to the environment by including these lines in your
.zshrc
fileI solved this problem trying with Python 3.9.13 on a virtual environment.
On a non-M1 mac, Python 3.10.2, I solved this with
brew install librdkafka
.If you are installing confluent-kafka inside Docker container on M1, this helped me.
I added these to my docker-compose.yml (according to https://stackoverflow.com/a/74020511/20575677 and https://github.com/confluentinc/confluent-kafka-python/issues/65#issuecomment-269964346)