Pythonリンクpresto

1786 ワード

目次
リンクprestoは以下のモジュールをインストールする必要があります
に質問
解決する
Anaconda 3.x 、Python3.x
リンクprestoは以下のモジュールをインストールする必要があります
conda install sasl
conda install thrift
conda install thrift-sasl
conda install PyHive
from sqlalchemy import *
from sqlalchemy.engine import create_engine
from sqlalchemy.schema import *
import pandas as pd
class Main():
    def __init__(self):
        pass

    def test_presto_connect(self):
        # Presto
        # host    ip,port   ,hive   Presto catalog,my_schema hive schema。
        engine = create_engine('presto://ip:port/hive/parquet')  
        print(engine)
        #    pandas              ,           。
        df = pd.read_sql("select * from table_name  limit 10", engine) 
        print(df)

    def test_presto_connect1(self):
        conn = prestodb.dbapi.connect(
            host='ip',
            port=port,
            user='root',
            catalog='hive',
            schema='parquet'
        )
        cur = conn.cursor()
        cur.execute("select * from table_name limit 10")
        rows = cur.fetchall()
        print(rows)



if __name__ == '__main__':
    m = Main()
    m.test_presto_connect1()

 
に質問
condaを使用してモジュールをインストール中にエラーが発生しました.ターゲットサーバが積極的に拒否するなどの問題があります.
解決する
1、condaはソースを交換して、別々にテストする必要がある
conda     

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --set show_channel_urls yes

conda     

conda config --remove-key channels


 
2、エージェントの試行をオフにしたり、Anaconda PromptでPythonのpip installコマンドを使用したりすることができます