[英]Kivy SQLalchemy and Android, No module named MySQLdb
我正在為Android開發一個應用程序,我需要與Mysql數據庫進行交互。 我在配置從android的訪問時遇到一些問題,但在我的linux安裝中卻沒有。
我已經在我的android apk上成功導入了SQLAlchemy的配方,但是當我通過logcat運行應用程序時,我看到了錯誤:
NO module named MySQLdb
所以我嘗試在buildozer中還添加MySQLdb的配方,它說:
No matching distribution found for MySQLdb
這是調用mysql部分的代碼的一部分:
import sqlalchemy
from sqlalchemy import create_engine
from sqlalchemy import MetaData, Column, Table, ForeignKey
from sqlalchemy import Integer, String
from sqlalchemy.sql import select
def check_sql_list(_id, string):
cur = engine.connect()
res = cur.execute("SELECT * FROM tbl_user")
for x in res.fetchall():
if x[_id] == string: return True
cur.close()
def create_user(name,e_mail,psw):
if check_sql_list(1,name):
print 'Select another username.'
elif check_sql_list(2,e_mail):
print 'Your E-Mail have already an account.'
else:
connection = engine.raw_connection()
try:
cursor = connection.cursor()
cursor.callproc("sp_createUser",[name, e_mail, psw])
results = list(cursor.fetchall())
for a in cursor.fetchall():
print a
print results
cursor.close
connection.commit()
finally:
connection.close()
print 'Account registered succesfully.'
ip = 'localhost'
databs = 'mydb'
user = 'guest'
psw = 'password'
porta = '3306'
engine = create_engine('mysql://' + user + ':' + psw + '@' + ip + ':' + porta + '/' + databs)
create_user('user001','mail@001.com','password')
如何無需MySQLdb配方連接到我的數據庫? 或者我在哪里可以找到那個食譜?
我回答我自己的問題,希望有人會覺得有用。
我發現如何解決它,用作mysql + mysqlconnector的撥號器,例如:
engine = create_engine('mysql+mysqlconnector://user00:psw@localhost:3306/database')
並在buildozer.spec中添加配方要求:
requirements = kivy,sqlalchemy,mysql_connector
kivy -m pip安裝mysql-connector
比:
導入mysql.connector
為我工作:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.