Pyhon 链接 hive数据库,需要导入的jar包
1.环境准备
win 10 64bit
python 37
2.jar下载
说明:.whl文件到http://www.lfd.uci.edu/~gohlke/pythonlibs/下载相应的python和windows版本
下载本地:D:\Ddocument
3.操作步骤
a.cmd下
b.切换到python目录下:cd C:\Users\tdc\AppData\Local\Programs\Python\Python37 \Scripts
c.依次执行
pip install six
pip install bit_array
pip install thriftpy ## thrift (on Python 2.x) or thriftpy (on Python 3.x)
pip install D:\Ddocument\sasl-0.2.1-cp37-cp37m-win_amd64.whl
pip install thrift_sasl
pip install D:\Ddocument\bitarray-1.2.0-cp37-cp37m-win_amd64.whl
pip install impyla
4.代码
from impala.dbapi import connect
from impala.util import as_pandas
conn = connect(host='***', port=10000, auth_mechanism='PLAIN', user='***', password='***', database='***')
cursor = conn.cursor()
cursor.execute('show databases')
print(as_pandas(cursor)
5.运行报错
TypeError: can’t concat str to bytes
修改文件
定位到 \Lib\site-packages\thriftpy\parser\parser.py的
原来:
if url_scheme == '':
with open(path) as fh:
data = fh.read()
elif url_scheme in ('http', 'https'):
data = urlopen(path).read()
else:
raise ThriftParserError('ThriftPy does not support generating module '
'with path in protocol \'{}\''.format(
url_scheme))
修改为:
if url_scheme == '':
with open(path) as fh:
data = fh.read()
elif url_scheme in ('c', 'd','e','f''):
with open(path) as fh:
data = fh.read()
elif url_scheme in ('http', 'https'):
data = urlopen(path).read()
else:
raise ThriftParserError('ThriftPy does not support generating module '
'with path in protocol \'{}\''.format(
url_scheme))
6.运行报错:
TypeError: can’t concat str to bytes
修改文件:
定位到定位到 \Lib\site-packages\thrift_sasl\__init__.py的
原来:
...
header = struct.pack(">BI", status, len(body))
self._trans.write(header + body)
...
修改为:
...
header = struct.pack(">BI", status, len(body))
if(type(body) is str):
body = body.encode()
self._trans.write(header + body)
...
7.运行成功