栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 云计算 > 云平台

通过pyhive连接hive需要的Python包

云平台 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

通过pyhive连接hive需要的Python包

1.通过pyhive连接hive需要的Python包:
3.1 pyhive
3.2 thrift
3.3 sasl
共需要三个包

2.连接Hive
from pyhive import hive
import pandas as pd
cnn=hive.Connection(host=‘localhost’, port=‘10000’, username=‘hive’)
cursor=cnn.cursor()
cursor.execute(“show databases”)
data=pd.DataFrame(cursor.fetchall())

其中sasl在Windows安装下安装需要编译环境,为了方便可直接从https://www.lfd.uci.edu/~gohlke/pythonlibs/#sasl下载编译好的包,直接进行安装,比如

C:>pip install sasl-0.2.1-cp37-cp37m-win_amd64.whl

安装完毕,执行代码会报以下错误

from pyhive import hive
conn = hive.Connection(host=‘172.100.0.11’,port=10000)
Traceback (most recent call last):
File “”, line 1, in
File “…Python37libsite-packagespyhivehive.py”, line 192, in init
self.transport.open()
File "…Python37libsite-packagesthrift_sasl_init
.py", line 79, in open
message=(“Could not start SASL: %s” % self.sasl.getError()))
thrift.transport.TTransport.TTransportException: Could not start SASL: b’Error in sasl_client_start (-12) SASL library is not initialized

【解决方案】
先直接贴出解决方案,后面再给出分析过程。在Windows中使用管理员权限打开控制台,在控制执行一段命令即可,操作如下。

C:Windowssystem32> FOR /F “usebackq delims=” %A IN (python -c "from importlib import util;import os;print(os.path.join(os.path.dirname(util.find_spec('sasl').origin),'sasl2'))") DO (
REG ADD “HKEY_LOCAL_MACHINESOFTWARECarnegie MellonProject CyrusSASL Library” /v SearchPath /t REG_SZ /d “%A”
)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/895592.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号