sublime+python+hive

安裝Python、安裝pip

安裝sublime、配置sublime

Package Control

SublimeREPL(使可以進行交互,例如input)

  • tools–>build system–>new build system–>修改爲如下代碼–>保存(例如命名爲python3.8)
{
	"encoding": "utf-8",  
	"working_dir": "$file_path",                                                                                      
	"shell_cmd": "C:\\Users\\lorog\\AppData\\Local\\Programs\\Python\\Python38\\python.exe -u \"$file\"",  
	"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",                                                             
	"selector": "source.python"                                                                                       
}
  • preferences–>key bindings–>修改爲如下代碼–>保存–>F5快捷鍵運行設置成功

!!!一定要先保存再運行

[
	{
		"keys":["f5"],  
		"caption": "SublimeREPL: Python - RUN current file",  
		"command": "run_existing_window_command", 
		"args": {"id": "repl_python_run",  "file": "config/Python/Main.sublime-menu"}
	}  
]

Autopep8(保存時格式化)

preferences–>setting

"format_on_save": true

連接hive

  1. 安裝依賴
pip install pure-sasl
pip install thrift_sasl==0.2.1 --no-deps
pip install thrift==0.9.3
pip install impyla
pip install thriftpy

安裝impyla時出現問題Microsoft Visual C++ 14.0 is required
在這裏插入圖片描述
解決方案
下載Microsoft Visual C++ 14.0

選擇默認方式安裝即可,電腦也不用重啓,直接pip安裝所需要的插件就行
地址:https://pan.baidu.com/s/18bjsvBIgBAhn5_6ApMcFew 密碼: zkzf

  1. 代碼
from impala.dbapi import connect
conn1=connect(host='XXXX',port=10000,database='js',auth_mechanism='PLAIN',user='root',password='123')
cur=conn1.cursor()
cur.execute('SHOW DATABASES')
print(cur.fetchall())

host: 地址
port:端口號
auth_mechanism=‘PLAIN’,一個很重要的參數,必要的
user:用戶名
password:密碼,可以沒有
database:數據庫名字

運行報錯TypeError: can’t concat str to bytes
解決方法

  • 按照錯誤,定位到init.py第94行,修改對於body的處理方式
header = struct.pack(">BI", status, len(body))
# 增加對於tody的類型判斷,做一些處理
if (type(body) is str):
  body = body.encode()
self._trans.write(header + body)
self._trans.flush()
  1. 成功
    在這裏插入圖片描述
發佈了71 篇原創文章 · 獲贊 12 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章