Kivy 应用程序在 Android 上崩溃,错误模块未找到 sklearn
我制作了简单的机器学习应用程序,可以预测土壤报告输入的作物。它在 Windows 上工作得很好,但是当使用推土机工具转换为 apk 并满足所有必需的要求时,它会因 logcat 错误模块未找到 sklearn 而崩溃,我已在 buildozer.spec 文件的要求中添加了 sklearn
Python 代码*
class SoilTest(Screen):
location = ObjectProperty()
nitrogen = ObjectProperty()
phosphorus = ObjectProperty()
potassium = ObjectProperty()
rain_fall = ObjectProperty()
ph = ObjectProperty()
temp = ObjectProperty()
humidity = ObjectProperty()
def submit_result(self):
global humi
humi=self.humidity.text
o=open("loc.csv","+a")
p = o.write(humi)
humi = float(humi)
global tem
tem=self.temp.text
p = o.write("\t")
p = o.write(tem)
tem=float(tem)
global p_h
p_h = self.ph.text
p = o.write("\t")
p = o.write(p_h)
p_h=float(p_h)
global fall
fall = self.rain_fall.text
p = o.write("\t")
p = o.write(fall)
fall=float(fall)
global pota
pota = self.potassium.text
p = o.write("\t")
p = o.write(pota)
pota=float(pota)
global phos
phos = self.phosphorus.text
p = o.write("\t")
p = o.write(phos)
phos=float(phos)
loc = self.location.text
data1 = o.write(loc)
global nitro
nitro = self.nitrogen.text
n = o.write('\t')
n = o.write(nitro)
nitro=float(nitro)
o.close()
def recommand(self):
x = [[nitro,phos,pota,tem,humi,p_h,fall]]
y_pred = mode.predict(x);
global cropi
cropi=(crop_name[y_pred[0]])
cropi=str(cropi)
print(cropi)
Kivy代码
<SoilTest>:
name:'soiltest'
location: loc
nitrogen: nitro
phosphorus: phosp
potassium: pota
rain_fall: rain
ph: pih
temp: temper
humidity: humi
BoxLayout:
orientation:'vertical'
MDTextField:
id: loc
hint_text:"Enter Location"
helper_text:"parameters"
icon_right:'android'
helper_text_mode:"on_focus"
icon_right_color: app.theme_cls.primary_color
pos_hint:{"center_x":0.5,"center_y":0.9}
size_hint_x:None
width:300
MDTextField:
id: nitro
hint_text:"Enter Nitrogen"
helper_text:"parameters"
icon_right:'android'
helper_text_mode:"on_focus"
icon_right_color: app.theme_cls.primary_color
pos_hint:{"center_x":0.5,"center_y":0.8}
size_hint_x:None
width:300
MDTextField:
id: phosp
hint_text:"Enter Phosphorus"
helper_text:"parameters"
icon_right:'android'
helper_text_mode:"on_focus"
icon_right_color: app.theme_cls.primary_color
pos_hint:{"center_x":0.5,"center_y":0.7}
size_hint_x:None
width:300
MDTextField:
id: pota
hint_text:"Enter Potasium"
helper_text:"parameters"
icon_right:'android'
helper_text_mode:"on_focus"
icon_right_color: app.theme_cls.primary_color
pos_hint:{"center_x":0.5,"center_y":0.6}
size_hint_x:None
width:300
MDTextField:
id: rain
hint_text:"Enter Rain_fall"
helper_text:"parameters"
icon_right:'android'
helper_text_mode:"on_focus"
icon_right_color: app.theme_cls.primary_color
pos_hint:{"center_x":0.5,"center_y":0.5}
size_hint_x:None
width:300
MDTextField:
id: pih
hint_text:"Enter PH of soil"
helper_text:"parameters"
icon_right:'android'
helper_text_mode:"on_focus"
icon_right_color: app.theme_cls.primary_color
pos_hint:{"center_x":0.5,"center_y":0.4}
size_hint_x:None
width:300
MDTextField:
id: temper
hint_text:"Enter Temprature"
helper_text:"parameters"
icon_right:'android'
helper_text_mode:"on_focus"
icon_right_color: app.theme_cls.primary_color
pos_hint:{"center_x":0.5,"center_y":0.3}
size_hint_x:None
width:300
MDTextField:
id: humi
hint_text:"Enter Humidity"
helper_text:"parameters"
icon_right:'android'
helper_text_mode:"on_focus"
icon_right_color: app.theme_cls.primary_color
pos_hint:{"center_x":0.5,"center_y":0.2}
size_hint_x:None
width:300
# BoxLayout:
# orientation:'vertical'
BoxLayout:
orientation:'horizontal'
MDFillRoundFlatButton:
text:"Submit"
pos_hint:{"center_x":.4,"center_y":.4}
size_hint_x:None
on_release:
root.submit_result()
root.recommand()
# (nitro,phosp,pota,temper,humi,pih,rain)
app.root.current='result'
BoxLayout:
orientation:'horizontal'
MDFillRoundFlatButton:
text:"Back"
pos_hint:{"center_x":.4,"center_y":.4}
size_hint_x:None
on_release:
app.root.current='first'
这是应用程序logcat的图像 Logcat
这是一些带有提交按钮的应用程序,按下此按钮后它会在 Android 上崩溃,但工作正常在 Windows 上
按应用预测的作物 裁剪
I have made simple machine learning app which predicts crop for soil report inputs . It works totally fine on windows but however when converted to apk using bulldozer tool with all required requirements it crashes with logcat error module not found sklearn , I have added sklearn in requirements of buildozer.spec file
Python code*
class SoilTest(Screen):
location = ObjectProperty()
nitrogen = ObjectProperty()
phosphorus = ObjectProperty()
potassium = ObjectProperty()
rain_fall = ObjectProperty()
ph = ObjectProperty()
temp = ObjectProperty()
humidity = ObjectProperty()
def submit_result(self):
global humi
humi=self.humidity.text
o=open("loc.csv","+a")
p = o.write(humi)
humi = float(humi)
global tem
tem=self.temp.text
p = o.write("\t")
p = o.write(tem)
tem=float(tem)
global p_h
p_h = self.ph.text
p = o.write("\t")
p = o.write(p_h)
p_h=float(p_h)
global fall
fall = self.rain_fall.text
p = o.write("\t")
p = o.write(fall)
fall=float(fall)
global pota
pota = self.potassium.text
p = o.write("\t")
p = o.write(pota)
pota=float(pota)
global phos
phos = self.phosphorus.text
p = o.write("\t")
p = o.write(phos)
phos=float(phos)
loc = self.location.text
data1 = o.write(loc)
global nitro
nitro = self.nitrogen.text
n = o.write('\t')
n = o.write(nitro)
nitro=float(nitro)
o.close()
def recommand(self):
x = [[nitro,phos,pota,tem,humi,p_h,fall]]
y_pred = mode.predict(x);
global cropi
cropi=(crop_name[y_pred[0]])
cropi=str(cropi)
print(cropi)
Kivy Code
<SoilTest>:
name:'soiltest'
location: loc
nitrogen: nitro
phosphorus: phosp
potassium: pota
rain_fall: rain
ph: pih
temp: temper
humidity: humi
BoxLayout:
orientation:'vertical'
MDTextField:
id: loc
hint_text:"Enter Location"
helper_text:"parameters"
icon_right:'android'
helper_text_mode:"on_focus"
icon_right_color: app.theme_cls.primary_color
pos_hint:{"center_x":0.5,"center_y":0.9}
size_hint_x:None
width:300
MDTextField:
id: nitro
hint_text:"Enter Nitrogen"
helper_text:"parameters"
icon_right:'android'
helper_text_mode:"on_focus"
icon_right_color: app.theme_cls.primary_color
pos_hint:{"center_x":0.5,"center_y":0.8}
size_hint_x:None
width:300
MDTextField:
id: phosp
hint_text:"Enter Phosphorus"
helper_text:"parameters"
icon_right:'android'
helper_text_mode:"on_focus"
icon_right_color: app.theme_cls.primary_color
pos_hint:{"center_x":0.5,"center_y":0.7}
size_hint_x:None
width:300
MDTextField:
id: pota
hint_text:"Enter Potasium"
helper_text:"parameters"
icon_right:'android'
helper_text_mode:"on_focus"
icon_right_color: app.theme_cls.primary_color
pos_hint:{"center_x":0.5,"center_y":0.6}
size_hint_x:None
width:300
MDTextField:
id: rain
hint_text:"Enter Rain_fall"
helper_text:"parameters"
icon_right:'android'
helper_text_mode:"on_focus"
icon_right_color: app.theme_cls.primary_color
pos_hint:{"center_x":0.5,"center_y":0.5}
size_hint_x:None
width:300
MDTextField:
id: pih
hint_text:"Enter PH of soil"
helper_text:"parameters"
icon_right:'android'
helper_text_mode:"on_focus"
icon_right_color: app.theme_cls.primary_color
pos_hint:{"center_x":0.5,"center_y":0.4}
size_hint_x:None
width:300
MDTextField:
id: temper
hint_text:"Enter Temprature"
helper_text:"parameters"
icon_right:'android'
helper_text_mode:"on_focus"
icon_right_color: app.theme_cls.primary_color
pos_hint:{"center_x":0.5,"center_y":0.3}
size_hint_x:None
width:300
MDTextField:
id: humi
hint_text:"Enter Humidity"
helper_text:"parameters"
icon_right:'android'
helper_text_mode:"on_focus"
icon_right_color: app.theme_cls.primary_color
pos_hint:{"center_x":0.5,"center_y":0.2}
size_hint_x:None
width:300
# BoxLayout:
# orientation:'vertical'
BoxLayout:
orientation:'horizontal'
MDFillRoundFlatButton:
text:"Submit"
pos_hint:{"center_x":.4,"center_y":.4}
size_hint_x:None
on_release:
root.submit_result()
root.recommand()
# (nitro,phosp,pota,temper,humi,pih,rain)
app.root.current='result'
BoxLayout:
orientation:'horizontal'
MDFillRoundFlatButton:
text:"Back"
pos_hint:{"center_x":.4,"center_y":.4}
size_hint_x:None
on_release:
app.root.current='first'
Here is the images of app logcat
Logcat
Here are some ss of app with submit button after pressing this it crashes on android but works fine on windows
Predicted crop by app
crop
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论