I've done a kivy app and I packaged to an .apk with buildozer. The fact is that now I want to package in a .exe for windows with Pyinstaller but I have realised that this two programs (buildozer and Pyinstaller), don't work in the same way. I've been looking for a good tutorial that could help me to get the file, but all the tutorials I have seen are too simple and don't explain for example how to import external files of the main.py
(e.g. images) and how to import external modules (In buildozer I had to add the libraries I wanted to the apk file to work properly). I'm working in Ubuntu ( Should I work in windows if I want to get an executable for windows?) and I have the list I added to my .apk to work properly. The list is:
requirements = kivy,sqlite3,requests,simplejson,icalendar,datetime,pytz,HTMLParser,email,openssl
If somebody could tell me how to add the another files (main.py
is the master file but I have 2 other files that are imported in main.py
) I would be very pleased, because I have tried a lot of times and untill doesn't work.
PyInstaller includes a hook for kivy that by default adds all the core modules used by kivy, e.g. audio, video, spelling etc (you still need to package the gstreamer dlls manually with Tree() - see the example above) and their dependencies.
PyInstaller generates the executable that is a bundle of your game. It puts it in the dist\ folder under your current working directory.
You have to run PyInstaller yourfile.spec on a windows environment. I can share a spec file I am using just as an example.
# -*- mode: python -*-
import os
from os.path import join
from kivy import kivy_data_dir
from kivy.deps import sdl2, glew
from kivy.tools.packaging import pyinstaller_hooks as hooks
block_cipher = None
kivy_deps_all = hooks.get_deps_all()
kivy_factory_modules = hooks.get_factory_modules()
datas = [
(join('common', '*.ini'), 'common')
]
# list of modules to exclude from analysis
excludes_a = ['Tkinter', '_tkinter', 'twisted', 'docutils', 'pygments']
# list of hiddenimports
hiddenimports = kivy_deps_all['hiddenimports'] + kivy_factory_modules
# binary data
sdl2_bin_tocs = [Tree(p) for p in sdl2.dep_bins]
glew_bin_tocs = [Tree(p) for p in glew.dep_bins]
bin_tocs = sdl2_bin_tocs + glew_bin_tocs
# assets
kivy_assets_toc = Tree(kivy_data_dir, prefix=join('kivy_install', 'data'))
source_assets_toc = Tree('images', prefix='images')
assets_toc = [kivy_assets_toc, source_assets_toc]
tocs = bin_tocs + assets_toc
a = Analysis(['yourmain.py'],
pathex=[os.getcwd()],
binaries=None,
datas=datas,
hiddenimports=hiddenimports,
hookspath=[],
runtime_hooks=[],
excludes=excludes_a,
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe1 = EXE(pyz,
a.scripts,
name='mywindowsapplication',
exclude_binaries=True,
icon=join('images', 'mywinapp.ico'),
debug=False,
strip=False,
upx=True,
console=False)
coll = COLLECT(exe1,
a.binaries,
a.zipfiles,
a.datas,
*tocs,
strip=False,
upx=True,
name='mywinapp')
Put the 'myfile.spec' file in the same directory where your 'yourmain.py' file is present. Then run PyInstaller myfile.spec from this directory. A build and a dist folder will be created. In the dist folder you may find your exe. Hope this gets you going.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With