通过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 “…\Python37\lib\site-packages\pyhive\hive.py”, line 192, in init
self.transport.open()
File "…\Python37\lib\site-packages\thrift_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:\Windows\system32> 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_MACHINE\SOFTWARE\Carnegie Mellon\Project Cyrus\SASL Library” /v SearchPath /t REG_SZ /d “%A”
)

datax 报错 File “datax.py”, line 114 print readerRef
解决方案:更换安装目录下bin的对应文件

datax.py, dxprof.y, perftrace.py

/home/datax/plugin/reader/._hdfsreader/plugin.json]不存在. 请检查您的配置文
解决:

但是并未在提示目录找到指定文件

需要通过命令行查看是否有._开头的文件

在datax/plugin目录下执行

find ./* -type f -name “._*er”

将查到的文件全部删除,可通过此命令执行

nd ./* -type f -name “._*er”|xargs rm -rf

再次运行命令即可正常执行 :)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值