i add python as data source in redash with no error
but when i wrote code there is a problem in importing python library
this is my code
def fun():
import mysql.connector
mydb = mysql.connector.connect(
host=“localhost”,
user=“root”,
passwd=“123speakol”,
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])
fun()

this get an error says:
Error running query: <type ‘exceptions.AttributeError’> ‘module’ object has no attribute 'connector’
@kyoshidajp @arikfr

@AmiraShaker Did you set mysql.connector to “Modules to import prior to running the script” in Python Data Source settings page?

@kyoshidajp yes i set it

@AmiraShaker Or can you import it from an interactive shell? Like this.

% python 
>>> import mysql.connector
>>>

inside shell there is no error
the problem still when i import it inside redash @kyoshidajp

@AmiraShaker It’s a strange story. What’s your version? How did you install Redash?

@kyoshidajp this is python version
3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56)
i followed the instruction in redash document

@AmiraShaker Can you downgrade Python 2.7? Probably, due to " Implicit Relative Import".

mysql is treated as query_runner (https://github.com/getredash/redash/blob/master/redash/query_runner/mysql.py), which don’t have connector.

Doc (https://redash.io/help/open-source/dev-guide) also says:

Redash is a Python (2.7) and Javascript app.

@kyoshidajp i installed python 2.7 so now i have 2 versions of python 2.7 & 3.6
or you mean uninstall python 3.6 and keep python 2.7 only ??

@AmiraShaker OK. You don’t need to uninstall 3.6. Try to activate 2.7 on Anaconda env. Then, restart Redash as 2.7.

@kyoshidajp i activate python to 2.7 using command “conda install python =2.7”
and reopen redash but the problem is still same
“module object has no attribute connector”

i activate python to 2.7 using command “conda install python=2.7”
and reopen redash but the problem is still same
“module object has no attribute connector " @kyoshidajp

How about checking your Python version on Python Data Source.

import sys
print sys.version

It might be 3.6. Of course, you have to add sys to “Modules to import prior to running the script”.

@kyoshidajp its 2.7.12 (default, Nov 19 2016, 06:48:10) not 3.6

is there another solution ?? @kyoshidajp

No, I don’t have for now.

@AmiraShaker Please try the following query on Redash.

import mysql
print mysql.__file__

I want to know where is your mysql path.

it gives me error
Error running query:<type ‘exceptions.SyntaxError’> Line 3: “file” is an invalid attribute name because it starts with “_” @kyoshidajp

@kyoshidajp is there another issue to solve this ??