python安装pyhs2遇到的问题
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python安装pyhs2遇到的问题,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1504字,纯文字阅读大概需要3分钟。
内容图文
![python安装pyhs2遇到的问题](/upload/InfoBanner/zyjiaocheng/590/89eafbcd5d3943a1a3c7c1a94012016c.jpg)
在使用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服务
内容总结
以上是互联网集市为您收集整理的python安装pyhs2遇到的问题全部内容,希望文章能够帮你解决python安装pyhs2遇到的问题所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。