如何在Redash中导入Python库

时间:2019-06-23 08:19:04

标签: python

我在Redash中添加Python作为数据源, 但是在导入“ MySQL.connector”模块时出现错误:

我关注了这篇文章: 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()

我收到此错误

  

错误运行查询:'module'   对象没有属性“连接器”

1 个答案:

答案 0 :(得分:0)

安装似乎已损坏。

尝试一下:

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

然后这个:

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

然后:

import mysql.connector