安装pyhive包
一、環境:Windows + Pycharm+ Python37
1、安裝pyhive包:sasl、thrift、thrift-sasl、PyHive
Pycharm的Terminal中運行:
其中sasl在Windows安裝下安裝需要編譯環境,為了方便可直接從Link下載編譯好的包,直接進行安裝,比如python37 64bit電腦選擇sasl-0.2.1-cp37-cp37m-win_amd64.whl:
pip install windos路徑/sasl-0.2.1-cp37-cp37m-win_amd64.whl2、安裝完畢,執行代碼會報以下錯誤
thrift.transport.TTransport.TTransportException: Could not start SASL: b'Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callback: 2'解決方案:
在Windows中使用管理員權限打開控制臺,在控制執行一段命令即可:
3、就可以使用pyhive來通過python連接hive了。
from pyhive import hiveconn = hive.Connection(host='xxx', port=xxx, username='xxx',password='xxx', database='xxx', auth='LDAP') cursor = conn.cursor() # cursor.execute('show tables') cursor.execute('select count(1) from xx.xxx where xxx="xxx"') for result in cursor.fetchall():print(result)二、環境:Linux + Python36
1、切換成 xxx 用戶 su xxx 2、查看python36路徑 which python36 3、切換成root用戶 exit 4、安裝pyhive /xxx/python36 -m pip install pyhive參考鏈接:[解決方案] Windows pyhive Could not start SASL
總結
- 上一篇: Code::Blocks 17.12 F
- 下一篇: python读取hive方案分析