Hbase环境参考上一章节
安装happybase
Pip install happybase
创建test.py,代码如下:
from pyspark.sql import SparkSession
import happybase
def hpbase():
spark = SparkSession.builder.appName('SparkHBaseRDD').master('local[*]').getOrCreate()
sc=spark.sparkContext
connection=happybase.Connection('localhost')
table=connection.table('test')
g=table.scan()
for k, d in g:
print(k, d)
if __name__ == '__main__':
hpbase()
提交代码执行的时候报错,Python2.7提示 can’t find module ‘warnings’,如下:
或者提示ImportError: No module named happybase
我这里的解决方式是安装python3,python2.7环境下安装happybase提示报错。安装python3后使用
Pip3 install happyhbase安装happyhbase包。/etc/spark/conf/spark-env.sh增加如下配置:
export PYSPARK_PYTHON=python3,spark启动环境指定使用python3。
再次提交代码,报错信息如下:
thriftpy2.transport.TTransportException: TTransportException(type=1, message="Could not connect to ('localhost', 9090)")
启动hbase thrift
#hbase thrift start
再次执行,输出成果: