Python Pyhive模块无法导入名称配置单元
我想使用pyhive将Python连接到hive。我正在使用下面的python脚本在本地服务器上执行Python Pyhive模块无法导入名称配置单元,python,python-2.7,hadoop,hive,pyhive,Python,Python 2.7,Hadoop,Hive,Pyhive,我想使用pyhive将Python连接到hive。我正在使用下面的python脚本在本地服务器上执行 #!/usr/bin/env python # coding: utf-8 from pyhive import hive from TCLIService.ttypes import TOperationState def mysql_connect(host, port, username): conn = hive.Connection(host=host, port=port, use
#!/usr/bin/env python
# coding: utf-8
from pyhive import hive
from TCLIService.ttypes import TOperationState
def mysql_connect(host, port, username):
conn = hive.Connection(host=host, port=port, username=username)
return conn.cursor()
cursor = mysql_connect("localhost", 50070, "hduser")
cursor.execute("show databases")
print_log(cursor)
我将pyhive呈现到位置/usr/local/lib/python2.7/dist包中,但我最终得到以下输出
vaibhav@vaibhav-Lenovo-G570:~/Desktop/Python/Automation$ ./pyhive_test.py
Traceback (most recent call last):
File "./pyhive_test.py", line 9, in <module>
cursor = mysql_connect("localhost", 50070, "hduser")
File "./pyhive_test.py", line 6, in mysql_connect
conn = hive.Connection(host=host, port=port, username=username)
File "/usr/local/lib/python2.7/dist-packages/pyhive/hive.py", line 131, in __init__
self._transport.open()
File "/usr/local/lib/python2.7/dist-packages/thrift_sasl/__init__.py", line 80, in open
status, payload = self._recv_sasl_message()
File "/usr/local/lib/python2.7/dist-packages/thrift_sasl/__init__.py", line 101, in _recv_sasl_message
payload = read_all_compat(self._trans, length)
File "/usr/local/lib/python2.7/dist-packages/thrift_sasl/six.py", line 31, in <lambda>
read_all_compat = lambda trans, sz: trans.readAll(sz)
File "/home/vaibhav/.local/lib/python2.7/site-packages/thrift/transport/TTransport.py", line 60, in readAll
chunk = self.read(sz - have)
File "/home/vaibhav/.local/lib/python2.7/site-packages/thrift/transport/TSocket.py", line 132, in read
message='TSocket read 0 bytes')
thrift.transport.TTransport.TTransportException: TSocket read 0 bytes
二,。从他们提到的链接中获得参考,在虚拟环境中使用它或使用干净的蟒蛇。它们中的任何一个都没有使用过,也不知道它将如何影响现有的配置
3.我使用sudo安装了Pyhive,因此我更改了权限,但仍然遇到相同的问题。您正在启动的文件名为
Pyhive.py
当你这样做的时候
from pyhive import hive
在pyhive.py
中,它将尝试从模块导入hive
,而不是从pyhive
库导入
请命名您正在启动的其他文件,并避免使用现有模块/库的名称
从:
导入名为spam的模块时,解释器首先搜索具有该名称的内置模块。如果未找到,它将在变量sys.path给定的目录列表中搜索名为spam.py的文件。sys.path从以下位置初始化:
- 包含输入脚本的目录(或当前目录)
- PYTHONPATH(目录名列表,语法与shell变量PATH相同)
- 与安装相关的默认设置
我把它改为pyhive_测试,仍然收到相同的错误。你能更新你的问题并添加新的错误消息吗?您是否确保不再在与
pyhive_test.py
相同的目录中有文件pyhive.py
?我看到您已更新了问题,但显然在同一目录中仍有文件pyhive.py
。请删除它。@codaholic似乎回答了您最初的问题“Python Pyhive模块无法导入名称hive”,而您现在遇到了与hive.Connection
不同的问题。如果你需要新问题的帮助,我建议你创建一个新问题,如果有助于解决原始问题,请接受我的回答。已接受。我将发布一个新问题,如果你知道这个新问题,请在那里发布你的答案
from pyhive import hive