Python Pyhive模块无法导入name hi

2024-09-30 13:27:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用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, 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包,但最终得到以下输出

^{pr2}$

编辑 1文件名已从Pyhive更改为Pyhive\u test

  1. 在pyhive.py已从目录中删除

尝试的可能解决方案: 1.安装了python2.7和python3.4两个版本。我 已卸载Python3.4,但文件夹似乎仍存在于 /usr/local/lib/。我运行了下面的一些命令来检查python的安装位置以及PYTHONPATH中可用的包

vaibhav@vaibhav-Lenovo-G570:~$ which -a python
/usr/bin/python
vaibhav@vaibhav-Lenovo-G570:~$ python -c "import sys, pprint; pprint.pprint(sys.path)"
['',
 '/home/vaibhav',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/home/vaibhav/.local/lib/python2.7/site-packages',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PILcompat',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/pymodules/python2.7',
 '/usr/lib/python2.7/dist-packages/ubuntu-sso-client']

2。从提到的链接得到了参考here他们提到在虚拟环境中使用它或者使用干净的水蟒。没有使用任何他们如何和不知道它将如何影响已经存在的配置。在

3.我使用sudo安装了Pyhive,因此我在link之后更改了权限,但仍然遇到了相同的问题。在


Tags: importhostportlibpackagesusrlocaldist
1条回答
网友
1楼 · 发布于 2024-09-30 13:27:07

您正在启动的文件名为pyhive.py。在

当你这么做的时候

from pyhive import hive

pyhive.py内,它将尝试从模块导入hive,而不是从pyhive库导入{}。在

请为要启动的文件命名,并避免使用现有模块/库的名称。在

docs

When a module named spam is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file named spam.py in a list of directories given by the variable sys.path. sys.path is initialized from these locations:

  • the directory containing the input script (or the current directory).
  • PYTHONPATH (a list of directory names, with the same syntax as the shell variable PATH).
  • the installation-dependent default.

相关问题 更多 >

    热门问题