简体   繁体   English

尝试通过在python中使用pyhs2连接到配置单元| 错误:ModuleNotFoundError:没有名为“ cloudera”的模块

[英]Try to connect to hive via using pyhs2 in python | Error : ModuleNotFoundError: No module named 'cloudera'

I am trying to connect to Hive from windows locally using python : below is the code that i used : 我正在尝试使用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() 

and execute that script via cmd : 并通过cmd执行该脚本:

python hive-connection-test.py

But I am getting error - 但是我出错了- 在此处输入图片说明

Do guys have any idea that has happened here!! 伙计们有什么想法发生在这里! they is not package called cloudera in python package library, i have search for it. 他们不是python软件包库中称为cloudera的软件包,我已对其进行搜索。

Sorry, but I'm only going to half solve this questions as I'm only halfway through fixing it myself... 抱歉,我只解决一半问题,因为我只是自己解决问题的一半。

connections.py (located in Lib/site-packages/pyhs2/)has an import: connections.py(位于Lib / site-packages / pyhs2 /中)具有导入:

from cloudera.thrift_sasl import TSaslClientTransport 从cloudera.thrift_sasl导入TSaslClientTransport

This is trying to import the thrift_sasl from the clouders subdirectory, so the syntax should actually be: 这是尝试从clouders子目录导入thrift_sasl,因此语法实际上应该是:

from .cloudera.thrift_sasl import TSaslClientTransport 从.cloudera.thrift_sasl导入TSaslClientTransport

You can go in and change it yourself, but then it turns out that thrift_sasl.py is trying cStringIO which is no longer available in Python 3.0... so trying to find a workaround for this now. 您可以自己进行更改,但是事实证明thrift_sasl.py正在尝试cStringIO,而该字符串在Python 3.0中不再可用...因此现在尝试查找解决方法。

Hope this helps you along. 希望这对您有所帮助。

The error was caused by the import statement used in pyhs2. 该错误是由pyhs2中使用的import语句引起的。 The import feature was supported by Python2 but not Python3. 导入功能受Python2支持,但不受Python3支持。 You can have a try using Python2.7 instead of Python3 (you are currently using). 您可以尝试使用Python2.7代替Python3 (当前正在使用)。

pyhs2 is no longer maintained for years, so it's better to use other alternatives such as PyHive which is supported by Dropbox official. pyhs2不再维护多年,因此最好使用其他替代方法,例如Dropbox官方支持的PyHive

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM