【linux】安装python依赖库confluent_kafka

想跑https://github.com/ghaughian/mongo-kafka-spark/blob/master/src/pub.py这个程序,发现没有confluent_kafka库

 

1.pip安装

pip install confluent_kafka

 

居然报错:

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

 

上网查,发现需要安装python-devel和librdkafka-devel

1.查看具体包名

yum list python-devel

python-devel.x86_64

2.安装

yum install python-devel.x86_64

librdkafka-devel安装同理。这两个安装好后再安装confluent_kafka就ok了

 

 

经验:如果提示gcc运行时xxx.h没有,就安装xxx-devel包!

 

librdkafka-devel安装时遇到了点问题。在centos7.3上,我直接用yum install librdkafka-devel.x86_64可以成功,可是在centos6.9(64位)上却找不到这个包。必须源码编译。

参考:http://www.linuxidc.com/Linux/2017-04/142573.htm

1.下载https://github.com/edenhill/librdkafka 

2.解压
unzip librdkafka-master.zip

3.对文件赋权

chmod 777 configure lds-gen.py

4.

./configure

5. 把Makefile.config里面的WITH_LDS=y这一行注释掉 (64位需要做这一步,否则会报错/bin/ld:librdkafka.lds:1: syntax error in VERSION script)

6. make 

7. make install

 

在centos6.9上手工安装了librdkafka并安装了confluent_kafka后,运行代码报错:找不到librdkafka.so.1

解决参考:http://ypf3027.iteye.com/blog/2007743

通过find找到librdkafka.so.1在/usr/local/lib/librdkafka.so.1中

先建立软链

 

ln -s /usr/local/lib/librdkafka.so.1 /usr/lib

 

再创建出动态装入程序(ld.so)所需的连接和缓存文件

sudo ldconfig

 



 

posted @ 2017-08-29 15:55  匡子语  阅读(7057)  评论(0编辑  收藏  举报