'Convert Kivymd code to .exe (Windows executable)
I tried so much to convert kivymd code into .exe by using PyInstaller
the error i getting was -modulenotfound no module named kivy.graphics.buffer while solving this error too many other error occured Temp//kivy_install//data//style.kv also not console is visible it direct crases
my kivy md code :
import os, sys
from kivy.resources import resource_add_path
from kivy.lang import Builder
from kivymd.app import MDApp
KV = '''
MDScreen:
MDIconButton:
icon: "language-python"
pos_hint: {"center_x": .5, "center_y": .5}
'''
class Example(MDApp):
def build(self):
return Builder.load_string(KV)
if __name__ == "__main__":
# these lines should be added
if hasattr(sys, '_MEIPASS'):
resource_add_path(os.path.join(sys._MEIPASS))
###
Example().run()
My spect file:
# -*- mode: python ; coding: utf-8 -*-
import sys
import os
from PyInstaller.building.build_main import *
path = os.path.abspath(".")
kivymd_repo_path = path.split("demos")[0]
sys.path.insert(0, kivymd_repo_path)
from kivy_deps import sdl2, glew
from kivymd import hooks_path as kivymd_hooks_path
added_files = [
]
a = Analysis(['main.py'],
pathex=['C:\\Program Files\\Python37\\Lib\\site-packages\\kivy'],
binaries=[],
datas=[],
hiddenimports=['kivy.weakmethod',
"libs.baseclass.bottom_app_bar",
"libs.baseclass.bottom_sheet",
"libs.baseclass.cards",
"libs.baseclass.chips",
"libs.baseclass.data_tables",
"libs.baseclass.dialog_change_theme",
"libs.baseclass.dialogs",
"libs.baseclass.drop_item",
"libs.baseclass.expansionpanel",
"libs.baseclass.filemanager",
"libs.baseclass.grid",
"libs.baseclass.home",
"libs.baseclass.list_items",
"libs.baseclass.md_icons",
"libs.baseclass.menu",
"libs.baseclass.navigation_drawer",
"libs.baseclass.pickers",
"libs.baseclass.refresh_layout",
"libs.baseclass.snackbar",
"libs.baseclass.stack_buttons",
"libs.baseclass.tabs",
"libs.baseclass.taptargetview",
"libs.baseclass.textfields",
"libs.baseclass.toggle_button",
"libs.baseclass.toolbar",
"libs.baseclass.user_animation_card",
"kivymd.stiffscroll",],
hookspath=[kivymd_hooks_path],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=None,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=None)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
debug=False,
strip=False,
upx=True,
name="mynaddddme",
console=True,
)
Solution 1:[1]
Your .spec
file seems overly complicated. Here is a main.spec
file that works for me and your 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 )
And just run pyinstaller main.spec
. This should create a single file executable main.exe
.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | John Anderson |