我在Kivy身上遇到了很大的问题。你能救我吗?
我为我公司开发了库存控制应用程序。我的公司使用Oracle数据库。我用Kivy编写代码,Python和我使用cx_Oracle来连接我们的数据库。它在我的PC上工作完美。但它不适用于我的Android手机。我使用Buildozer构建了一个APK。我拿错误后,写日志。这是我得到的错误:
python : ImportError: No module named cx_Oracle
我的Android手机未找到cx_Oracle。我没有在手机上访问Oracle数据库,应用程序无法运行。有什么方法可以建议吗?
#!/usr/local/bin/python
# -*- coding: UTF-8 -*-
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen, SlideTransition
from kivy.uix.relativelayout import RelativeLayout
from kivy.properties import StringProperty
from kivy.network.urlrequest import UrlRequest
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.dropdown import DropDown
from kivy.uix.textinput import TextInput
from kivy.properties import ListProperty
from kivy.uix.floatlayout import FloatLayout
import cx_Oracle
import os, sys
Builder.load_string('''
#:import Button kivy.uix.button.Button
<GirisEkrani>:
BoxLayout:
id: login_layout
orientation: 'vertical'
padding: [10,50,10,50]
spacing: 50
BoxLayout:
orientation: 'vertical'
Label:
text: '*'
font_size: 18
halign: 'left'
text_size: root.width-20, 20
TextInput:
id: username
multiline:False
font_size: 28
BoxLayout:
orientation: 'vertical'
Label:
text: '*'
halign: 'left'
font_size: 18
text_size: root.width-20, 20
TextInput:
id: passwd
multiline:False
password:True
font_size: 28
Button:
text: "*"
font_size: 24
on_press: root.login()
<GirisOnayEkrani>:
karsilama_yazisi: karsilama_yazisi
BoxLayout:
id: kutu
orientation: "vertical"
padding: [10,50,10,50]
spacing: 50
Image:
source: "./dogru.png"
Label:
id: karsilama_yazisi
text: "*"
Button:
text: "Stok Kontrol"
font_size: 24
on_press: root.envanter()
Button:
text: "*"
font_size: 24
on_press: root.talepsikayet()
<GirisRedEkrani>:
BoxLayout:
orientation: "vertical"
Image:
source: "./yanlis.png"
Label:
text: "*"
Button:
text: "*"
on_press: root.anaEkranaDon()
<EnvanterKontrolEkrani>:
BoxLayout:
orientation: "vertical"
padding: [50,150,50,150]
spacing: 300
Button:
text: "*"
size_hint_y: None
font_size: 20
on_press: root.ekle()
AnchorLayout:
anchor_x: 'center'
anchor_y: 'center'
ScrollView:
size_hint_y: None
height: '500dp'
MyGrid:
cols: 3
size_hint_y: None
height: self.minimum_height
spacing: '2dp'
<EklemeEkrani>:
BoxLayout:
id: login_layout
orientation: 'vertical'
padding: [10,50,10,50]
spacing: 30
BoxLayout:
orientation: 'vertical'
Label:
text: "*"
font_size: 18
halign: 'left'
text_size: root.width-20, 20
TextInput:
id: partno
multiline:False
font_size: 28
BoxLayout:
orientation: 'vertical'
Label:
text: '*'
halign: 'left'
font_size: 18
text_size: root.width-20, 20
TextInput:
id: miktar
multiline:False
font_size: 28
BoxLayout:
orientation: 'vertical'
Label:
text: '*'
halign: 'left'
font_size: 18
text_size: root.width-20, 20
TextInput:
id: tarih
multiline:False
font_size: 28
Button:
text: "*"
font_size: 24
on_press: root.eklemek()
<TalepSikayetEkrani>:
BoxLayout:
id: login_layout
orientation: 'vertical'
padding: [10,50,10,50]
spacing: 15
BoxLayout:
orientation: 'vertical'
Label:
text: '*'
halign: 'left'
font_size: 16
text_size: root.width-20, 20
ComboEdit:
id: birim
multiline:False
font_size: 20
options:
[Button(text = '*', size_hint_y=None, height=30),
Button(text = '*', size_hint_y=None, height=30),
Button(text = '*', size_hint_y=None, height=30)]
BoxLayout:
orientation: 'vertical'
Label:
text: '*'
halign: 'left'
font_size: 16
text_size: root.width-20, 20
ComboEdit:
id: form
multiline:False
font_size: 20
options:
[Button(text = '*', size_hint_y=None, height=30),
Button(text = '*', size_hint_y=None, height=30),
Button(text = '*', size_hint_y=None, height=30)]
BoxLayout:
orientation: 'vertical'
Label:
text: '*'
halign: 'left'
font_size: 16
text_size: root.width-20, 20
ComboEdit:
id: onem
multiline:False
font_size: 20
options:
[Button(text = '*', size_hint_y=None, height=30),
Button(text = '*', size_hint_y=None, height=30),
Button(text = '*', size_hint_y=None, height=30)]
BoxLayout:
orientation: 'vertical'
Label:
text: '*'
halign: 'left'
font_size: 18
text_size: root.width-20, 20
TextInput:
id: konu
multiline:False
font_size: 20
BoxLayout:
orientation: 'vertical'
Label:
text: '*'
halign: 'left'
font_size: 18
text_size: root.width-20, 20
TextInput:
id: mesaj
multiline:False
font_size: 20
Button:
text: "*"
font_size: 24
on_press: root.formekle()
<TalepSikayetOnayEkrani>:
karsilama_yazisi: karsilama_yazisi
BoxLayout:
id: kutu
orientation: "vertical"
padding: [10,50,10,50]
spacing: 50
Image:
source: "./true.png"
Label:
id: karsilama_yazisi
text: "*"
Button:
text: "Anasayfaya Don"
font_size: 24
on_press: root.anasayfa()
<PlayerRecord>:
size_hint_y: None
height: '30dp'
width: '100dp'
canvas.before:
Color:
rgb: 0.2, 0.2, 0.2
Rectangle:
pos: self.pos
size: self.size
<RootWidget>:
canvas.before:
Color:
rgba: 0, 0, 0, 1
Rectangle:
pos: self.pos
size: self.size
id: kok
GirisEkrani:
id: giris
name: "giris_ekrani"
GirisOnayEkrani:
id: onay
name: "giris_basarili"
GirisRedEkrani:
id: red
name: "giris_hatali"
EnvanterKontrolEkrani:
id:envanter
name: "envanter_kontrol"
EklemeEkrani:
id:ekle
name: "ekleme"
TalepSikayetEkrani:
id:talepsikayet
name: "talep_sikayet"
TalepSikayetOnayEkrani:
id:talepsikayetonay
name: "talep_onay"
''')
class GirisEkrani(Screen):
def login(self):
if self.ids.username.text == "*" and\
self.ids.passwd.text == "*":
self.manager.current = "giris_basarili"
else:
self.manager.current = "giris_hatali"
class GirisOnayEkrani(Screen):
def envanter(self):
self.manager.current = "envanter_kontrol"
def talepsikayet(self):
self.manager.current = "talep_sikayet"
class EnvanterKontrolEkrani(Screen):
def ekle(self):
self.manager.current = "ekleme"
class TalepSikayetEkrani(Screen):
def formekle(self):
if len(self.ids.birim.text) > 0 and\
len(self.ids.form.text) > 0 and\
len(self.ids.onem.text) > 0 and\
len(self.ids.konu.text) > 0 and\
len(self.ids.mesaj.text) > 0:
con = cx_Oracle.connect('*/*@*/*')
rows = [(str(self.ids.birim.text), str(self.ids.form.text), str(self.ids.onem.text), str(self.ids.konu.text), str(self.ids.mesaj.text))]
cur = con.cursor()
cur.executemany("INSERT INTO * (birim , form, onem, konu, mesaj) VALUES (:1, :2, :3, :4, :5)", rows)
con.commit()
self.manager.current = "talep_onay"
self.ids.birim.text = ""
self.ids.form.text = ""
self.ids.onem.text = ""
self.ids.konu.text = ""
self.ids.mesaj.text = ""
else:
self.manager.current = "giris_hatali"
class ComboEdit(TextInput):
options = ListProperty(('', ))
def __init__(self, **kw):
ddn = self.drop_down = DropDown()
ddn.bind(on_select=self.on_select)
super(ComboEdit, self).__init__(**kw)
def on_options(self, instance, value):
ddn = self.drop_down
ddn.clear_widgets()
for widg in value:
widg.bind(on_release=lambda btn: ddn.select(btn.text))
ddn.add_widget(widg)
def on_select(self, *args):
self.text = args[1]
def on_touch_up(self, touch):
if touch.grab_current == self:
self.drop_down.open(self)
return super(ComboEdit, self).on_touch_up(touch)
class TalepSikayetOnayEkrani(Screen):
def anasayfa(self):
self.manager.current = "giris_ekrani"
class EklemeEkrani(Screen):
def eklemek(self):
if len(self.ids.partno.text) > 1 and\
len(self.ids.miktar.text) > 1 and\
len(self.ids.tarih.text) > 1:
con = cx_Oracle.connect('*/*@*/*')
rows = [(str(self.ids.partno.text), str(self.ids.miktar.text), str(self.ids.tarih.text))]
cur = con.cursor()
cur.executemany("INSERT INTO * (part_no, qty_on_hand, tarih) VALUES (:1, :2, :3)", rows)
con.commit()
self.manager.current = "giris_basarili"
self.ids.partno.text = ""
self.ids.miktar.text = ""
self.ids.tarih.text = ""
else:
self.manager.current = "giris_hatali"
class GirisRedEkrani(Screen):
def anaEkranaDon(self):
self.manager.current = "giris_ekrani"
class RootWidget(ScreenManager):
pass
class TableHeader(Label):
pass
class PlayerRecord(Label):
pass
class MyGrid(GridLayout):
def __init__(self, **kwargs):
super(MyGrid, self).__init__(**kwargs)
self.fetch_data_from_database()
self.display_scores()
def fetch_data_from_database(self):
con = cx_Oracle.connect('*/*@*/*')
cur=con.cursor()
cur.execute('''select part_no, qty_on_hand, tarih from *''')
liste =[{'Part No': 'Part No', 'Quantity On Hand': 'Quantity On Hand', 'Expiration Date': 'Expiration Date'}]
for result in cur:
liste.append({'Part No': result[0], 'Quantity On Hand': str(result[1]), 'Expiration Date': str(result[2])})
self.data = liste
def display_scores(self):
self.clear_widgets()
for i in range(len(self.data)):
row = self.create_player_info(i)
for item in row:
self.add_widget(item)
def create_player_info(self, i):
first_column = PlayerRecord(text=self.data[i]['Part No'])
second_column = PlayerRecord(text=self.data[i]['Quantity On Hand'])
third_column = PlayerRecord(text=self.data[i]['Expiration Date'])
return [first_column, second_column, third_column]
class CemApp(App):
def build(self):
return RootWidget()
if __name__ in ('__main__','__android__'):
CemApp().run()
注意:我用&#34; *&#34;
隐藏了公司数据答案 0 :(得分:0)
您需要在APK中包含cx_Oracle模块。但是,cx_Oracle是一个已编译的C模块,因此python-for-android需要recipe才能编译它(参考here是所有现有的配方)。还没有这样的配方,但你可以尝试写一个。您可能需要CompiledComponentsPythonRecipe。