简体   繁体   中英

How to import Python library in redash

I add Python as data source in redash, but when import 'MySQL.connector' module I get an error:

I followed this article: http://kzkohashi.hatenablog.com/entry/2017/12/09/224516

def read_sql(): 
    import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="******",database="testing")
    mycursor = mydb.cursor()
    mycursor.execute("select hour,sum(temperature) as temperature ,sum(wind_speed) as wind_speed from weatherdaat group by hour")
    myresult = mycursor.fetchall()
    for x in myresult: 
       print(x[0],x[1],x[2])  
read_sql()

I get this error

Error running query: <type 'exceptions.AttributeError'> 'module' object has no attribute 'connector'

The installation seems broken.

Try this:

pip uninstall mysql-connector
pip uninstall mysql-connector-python

Then this:

pip install mysql-connector
# OR
pip install mysql-connector-python

And then:

import mysql.connector 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM