pythonkivykivymdauto-py-to-exe

Python kivy doesn't work when I convert my code to exe


As a code, it works without any problems but when I convert it to exe, I get Unable to get window, abort error I tried all the solutions I found in the forums Can a person who can convert this code to exe for me tell me how he did it?

from kivymd.app import MDApp
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.image import Image
from kivy.clock import Clock
from kivymd.uix.textfield import MDTextField
from kivymd.uix.button import MDFloatingActionButton


class main(BoxLayout,MDApp):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.orientation = "vertical"
        self.a = MDTextField(size_hint_y=.1, hint_text="Write for translate", helper_text="Press the button for translate",helper_text_mode="on_focus", icon_right="cursor-text", size_hint_x=None, width=300,pos_hint={'center_x':0.5,'center_y':0.96})
        self.add_widget(self.a)
        self.b = MDFloatingActionButton(size_hint_y=.1, icon='translate',pos_hint={'center_x':0.5,'center_y':0.96})
        self.add_widget(self.b)
        self.b.bind(on_release=self.show_data)
        self.layout = BoxLayout(size_hint_y=.8)
        self.add_widget(self.layout)

    def show_data(self, show):
        self.list = self.a.text.split()
        for i in range(len(self.list)):
            if not self.list[i].endswith(".png"):
                self.list[i] += ".png"
        print(self.list)
        Clock.schedule_once(self.call)

    def call(self, call):
        self.numb = 0
        Clock.schedule_interval(self.do, 0.7)

    def do(self, do):
        if (self.numb < len(self.list)):
            self.layout.clear_widgets()
            self.layout.add_widget(Image(source=self.list[self.numb]))
            self.numb += 1
        else:
            self.numb = 0
            self.list = [self.a.text]
            Clock.unschedule(self.do)
            self.layout.clear_widgets()


class app(MDApp):
    def build(self):
        return main()


if __name__ == "__main__":
    app().run()

I tried with Cx_freeze , uninstalling kivy and other things can someone convert to exe?


Solution

  • I successfully converted your code to an exe using pyinstaller. Here is the spec file that I used (it assumes that your python file is named main.py):

    # -*- mode: python ; coding: utf-8 -*-
    
    from kivy_deps import sdl2, glew
    
    block_cipher = None
    
    
    a = Analysis(['main.py'],
                 pathex=[],
                 binaries=[],
                 datas=[],
                 hiddenimports=[],
                 hookspath=[],
                 hooksconfig={},
                 runtime_hooks=[],
                 excludes=[],
                 win_no_prefer_redirects=False,
                 win_private_assemblies=False,
                 cipher=block_cipher,
                 noarchive=False)
    pyz = PYZ(a.pure, a.zipped_data,
                 cipher=block_cipher)
    
    exe = EXE(pyz,
              a.scripts,
              a.binaries,
              a.zipfiles,
              a.datas,  
              *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
              name='main',
              debug=False,
              bootloader_ignore_signals=False,
              strip=False,
              upx=True,
              upx_exclude=[],
              runtime_tmpdir=None,
              console=True,
              disable_windowed_traceback=False,
              target_arch=None,
              codesign_identity=None,
              entitlements_file=None )
    

    Note the kivy_deps inclusion.