欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Win10 Python3.6 安装impyla

程序员文章站 2022-03-20 14:50:56
...
  • 安装依赖

  • pip install six

  • pip install bit_array

  • pip install thrift

  • pip install thriftpy

  • pip install impyla

  •  

当安装依赖有vs的python包时,可能会出现以下错误:

PermissionError: [WinError 32] 另一个程序正在使用此文件,进程无法访问。: 'C:\\Users\\15875\\AppData\\Local\\Temp\\pip-build-h3ir43bb\\murmurhash'

因为windowns下的终端显示用的还是gbk编码,所以还得修改pip的源代码

根据报错信息,找到 D:\Python36\Lib\site-packages\pip-7.1.0-py3.6.egg\pip\compat\__init__.py

第49行

f sys.version_info >= (3,):
    def console_to_str(s):
        try:
            return s.decode(sys.__stdout__.encoding)
        except UnicodeDecodeError:
            return s.decode('utf_8')


return s.decode('utf_8')改为return s.decode('cp936') 即可。

 

安装成功后

执行代码

from impala.dbapi import connect
conn = connect(host='my.host.com', port=21050)
cursor = conn.cursor()
cursor.execute('SELECT * FROM mytable LIMIT 100')
print cursor.description  # prints the result set's schema
results = cursor.fetchall()

报错

File 
    import happybase
  File "D:\Program Files\python3.6\lib\site-packages\happybase\__init__.py", line 10, in <module>
    'Hbase_thrift')
  File "D:\Program Files\python3.6\lib\site-packages\thriftpy\parser\__init__.py", line 30, in load
    include_dir=include_dir)
  File "D:\Program Files\python3.6\lib\site-packages\thriftpy\parser\parser.py", line 496, in parse
    url_scheme))
thriftpy.parser.exc.ThriftParserError: ThriftPy does not support generating module with path in protocol 'd'

 

ThriftParserError: ThriftPy does not support generating module with path in protocol 'd'

 

解决方法: 
进入如下 你的Python的安装路径下,找到parser.py文件 
D:\Program Files\python3.6\Lib\site-packages\thriftpy\parser

打开parser.py文件,找到488行。注释掉原来488行代码,添加为

if len(url_scheme) <= 1:
  •  

或者可以修改为 
if url_scheme in ('f', ''): 
如果是报错’d’上面就写’d’,‘f’就写’f’

#if url_scheme == '':
    if url_scheme in ('d', 'c','','e','f'):
        with open(path) as fh:
            data = fh.read()
    elif url_scheme in ('http', 'https'):
        data = urlopen(path).read()
    else:
        raise ThriftParserError('ThriftPy does not support generating module '
                                'with path in protocol \'{}\''.format(
                                    url_scheme))

 

 

问题原因 
原因:happybase1.0在win下不支持绝对路径 
具体原因:happybase要读取Python\Lib\site-packages\happybase\Hbase.thrift,但在Python\Lib\site-packages\thriftpy\parser\parser.py中的487行 
path是Hbase.thrift的绝对路径(我的是“F:\SoftWare\Python27\Lib\site-packages\happybase\Hbase.thrift”),但经过urlparse(path).scheme后,url_scheme变成了“f”,(这也就是报错信息中最后的“f”)。根据代码,url_scheme既不为“”,也不包含 
(‘http’,’https’),则只能为raise报错。

相关标签: python