centos 离线安装confluent_kafka 模块

centos 离线安装confluent_kafka 模块

背景:需要安装Python模块的机子不能上网,只能下载源码进行安装
说明:如果可以上网直接pip install confluent_kafka 即可

需安装模块:

confluent_kafka  #confluent_kafka 依赖librdkafka 模块:
librdkafka

安装包下载:

https://pypi.org/project/confluent-kafka/
https://github.com/edenhill/librdkafka

安装:
先安装librdkafka 模块:

cd  librdkafka 
./configure --prefix=/usr
make
make install
ldconfig

再安装confluent_kafka 模块:

cd  confluent_kafka
python setup.py install

测试:

import confluent_kafka

如果出现错误

    from .cimpl import (Consumer,  # noqa
ImportError: librdkafka.so.1: cannot open shared object file: No such file or directory

解决办法:

ldconfig

如果出现错误

confluent_kafka/src/confluent_kafka.h:21:32: fatal error: librdkafka/rdkafka.h: No such file or directory
 #include <librdkafka/rdkafka.h>
                                ^
compilation terminated.
error: command 'gcc' failed with exit status 1

解决办法:

./configure --prefix=/usr #增加前缀
make
make -j
make install
ldconfig 
#如果仍报错,在本机搜索librdkafka/rdkafka.h是否存在,如果已经存在,那么退出或者新建一个终端重新尝试即可

如果出现错误

In file included from confluent_kafka/src/confluent_kafka.c:17:0:
    confluent_kafka/src/confluent_kafka.h:17:20: fatal error: Python.h: No such file or directory
     #include <Python.h>
                        ^
    compilation terminated.
    error: command 'gcc' failed with exit status 1

解决办法:

yum install python-dev

参考链接:
https://blog.csdn.net/qq_35887983/article/details/79308723
https://github.com/confluentinc/confluent-kafka-python/issues/184
https://github.com/confluentinc/confluent-kafka-python/issues/65

猜你喜欢

转载自blog.csdn.net/marywang56/article/details/81744722