需要安装sqlalchemy和pyhive库。
下载wheel的命令:
pip2 wheel --trusted-host pypi.douban.com -i http://pypi.douban.com/simple -r python-dependencies.txt -w packs
其中packs为wheel下载到的目录,python-dependencies.txt为要下载的库列表文件,格式如下:
-----
pandas==0.23.4
numpy==1.16.0
sqlalchemy
pyhive==0.2.0
thrift=0.9.3
-----
或者通过下载特定版本包的tar.gz文件,然后通过pip install xxx.tar.gz获得打包的wheel
如果出现TCLIService找不到这样的错误,需要更新thrift为新版本,方法如下:
#查看老版本,卸载老版本,按照新版本
pip show thrift
pip uninstall thrift
pip install thrift-x.x.x*.whl
遇到thrift_sasl/sasl/pyhive版本不兼容的问题,就切换高或者低版本的重新安装,直到下面代码可以正确运行:
-----------
import pandas as pd
from sqlalchemy import create_engine
engine = create_engine("hive://host_name_xxx:10000/db_name_xxx")
sql = "select * from tbl_xxx where col_xxx = '2020-08-18'"
addrs = pd.read_sql(sql, engine)
-------------
如果遇到库的wheel格式版本号为cp27mu,但是python27的版本只支持cp27m的二字节,不支持cp27mu的四字节编码,则需要用python: ./configure --enable-unicode=ucs4重新编译python库使之支持对应cp27mu的usc4四字节编码。