一、导包
Settings => project interpreter =>
impyla 0.17a1 pure-sasl 0.6.2 thrift thrift-sasl
(manage repositories:https://pypi.douban.com/simple/)
(options:--trusted-host pypi.douban.com)
1)impyla
出现问题:microsoft visual c++ 14.0 is required
解决:下载链接 => https://pan.baidu.com/s/1-VTGzPA-RS6eIIqgiRO4yg
2)sasl => 由于发现pip list中有sasl而依旧报错sasl找不到,故放弃,选择impyla的连接hive方法
步骤一:查看python支持的whl版本:https://www.cnblogs.com/zhyantao/p/10424902.html
步骤二:下载whl地址: https://www.lfd.uci.edu/~gohlke/pythonlibs/
步骤三:pip安装whl文件:
cmd cd /D d:softwarepythonjdkScripts pip install --target=/usr/local/lib/python2.7/site-packages sasl-0.2.1-cp36-cp36m-win_amd64.whl
二、代码
from impala.dbapi import connect if __name__ == '__main__': conn = connect(host='192.168.56.111' ,database='default' , port=10000 , user='root' ,password='root' ,auth_mechanism='LDAP') cursor = conn.cursor() cursor.execute('select * from load_details limit 10') for result in cursor.fetchall(): print(result) conn.close() # print(pip._internal.pep425tags.get_supported())
成功: