python安装pyhs2遇到的问题

在使用python开发连接hiveserver2的过程中,需要安装pyhs2库,在使用pip安装pyhs2的过程中遇到了几个错误

1. gcc: error trying to exec 'cc1plus': execvp: 没有那个文件或目录

解决方法  在centos系统执行命令

    yum install -y gcc-c++ 

.即可解决

 

2. sasl/saslwrapper.h:22:23: 致命错误:sasl/sasl.h:没有那个文件或目录

解决方法 yum -y install cyrus-sasl cyrus-sasl-devel cyrus-sasl-lib

 

安装编译完pyhs2库后,执行以下代码

# -*- coding: utf-8 -*-
 
import pyhs2
import sys
 
default_encoding = 'utf-8'
if sys.getdefaultencoding() != default_encoding:
    reload(sys)
    sys.setdefaultencoding(default_encoding)
 
class HiveClient:
    def __init__(self,db_host,user,password,database,port=10008,authMechanism="PLAIN"):
        """
        create connection to hive server2
        """
        self.conn = pyhs2.connect(host=db_host,
                                  port=port,
                                  authMechanism=authMechanism,
                                  user=user,
                                  password=password,
                                  database=database,)
 
    def query(self, sql):
 
        """
        query
        """
        with self.conn.cursor() as cursor:
            cursor.execute(sql)
            return cursor.fetch()
 
    def close(self):
        """
        close connection
        """
        self.conn.close()
if __name__ == '__main__':
    hive_client = HiveClient(db_host='127.0.0.1',port=10000,user='hdfs',password='hyxy123',database='default', authMechanism='PLAIN')
    sql = "show tables"
    result = hive_client.query(sql)
    print result
    hive_client.close()

3 执行以上代码可能会报 

thrift.transport.TTransport.TTransportException: Could not start SASL: Error in sasl_client_start (-4) SASL(-4): no mechanism available: No worthy mechs found

解决方法 执行命令

yum -y install cyrus-sasl-plain

即可解决连接hiveserver服务
 

上一篇:kafka详细总结(五)


下一篇:python安装django-auth-ldap报错fatal error: sasl/sasl.h: No such file or directory