Kivy 应用程序在 Android 上崩溃,错误模块未找到 sklearn

发布于 2025-01-10 05:33:26 字数 5962 浏览 1 评论 0原文

我制作了简单的机器学习应用程序,可以预测土壤报告输入的作物。它在 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

Soil reports

Predicted crop by app
crop

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文