尝试在python中使用pyhs2连接到hive |错误:ModuleNotFoundError:没有名为“cloudera”的模块

问题描述 投票:0回答:3

我正在尝试使用 python 从 Windows 本地连接到 Hive:下面是我使用的代码:

import pyhs2 as hive
DEFAULT_DB = 'default'
DEFAULT_SERVER = '10.37.40.1'
DEFAULT_PORT = 10000
DEFAULT_DOMAIN = 'PAM01-PRD01.IBM.COM'
u = "username"
s = "password"
# Build the Hive Connection
connection = hive.connect(host=DEFAULT_SERVER, port= DEFAULT_PORT, user=u + '@' + DEFAULT_DOMAIN, password=s)
# Hive query statement
statement = "select * from user_yuti.Temp_CredCard where pir_post_dt = '2014-05-01' limit 100"
cur = connection.cursor()

# Runs a Hive query and returns the result as a list of list
cur.execute(statement)
df = cur.fetchall() 

并通过cmd执行该脚本:

python hive-connection-test.py

但我收到错误 -

大家知道这里发生了什么吗?它们不是Python包库中名为cloudera的包,我已经搜索过它。

python-3.x hive
3个回答
3
投票

该错误是由pyhs2中使用的

import
语句引起的。 Python2 支持导入功能,但 Python3 不支持。您可以尝试使用
Python2.7
代替
Python3
(您当前正在使用)。

pyhs2 已不再维护多年,因此最好使用其他替代方案,例如 Dropbox 官方支持的

PyHive


2
投票

抱歉,但我只会解决一半的问题,因为我自己只解决了一半......

connections.py(位于 Lib/site-packages/pyhs2/ 中)有一个导入:

从cloudera.thrift_sasl导入TSaslClientTransport

这是尝试从 clouders 子目录导入 thrift_sasl,因此语法实际上应该是:

从.cloudera.thrift_sasl导入TSaslClientTransport

你可以自己进去修改它,但事实证明 thrift_sasl.py 正在尝试 cStringIO,它在 Python 3.0 中不再可用......所以现在试图找到解决方法。

希望这对您有所帮助。


0
投票

正确的解决方案是切换到PyHive。 Pyhs2 不再更新,不支持 Python 3。

https://kyuubi.readthedocs.io/en/master/client/python/pyhive.html https://pypi.org/project/PyHive/

© www.soinside.com 2019 - 2024. All rights reserved.