This time, I tried to distribute an application that implements the function to display graphs with GUI by Kivy. I got caught a little, so as a memorandum. Environment is Windows 10
Import Kivy-Garden to enable matplotlib in Kivy. Later, it will be converted to an exe with pyinstaller, but at that time it seems that the garden directory will be lost, so Install matplotlib using --kivy.
$ pip install kivy-garden
$ garden install matplotlib --kivy
Install only the minimum required libraries with pip in a virtual environment. (Omitted for anaconda, pyenv, and virtual environment construction) If there are many unnecessary things, a huge exe file of 200 to 300 Mb will be born ...
$ pip install pyinstaller pypiwin32 #These two are essential
#These guys don't follow the kivy installation so don't forget if you haven't done so.
$ pip install kivy_deps.sdl2 kivy_deps.glew
$pip install required libraries#All required libraries for py files
I'm ready. Move your working directory to a python file and do the following: pyinstaller has various useful packaging functions, but here Use --onefile to combine files into one.
$ pyinstaller ***.py --onefile
Various things are generated in the working directory, but for the time being, an exe file is generated without dist. In this state, the GUI does not start yet.
#In the working directory
***.py
***.kv
***.spec
dist
pycache
build
Next, describe the dependencies in the SPEC file to enable the GUI.
#Below spec file
> ***.spec
from kivy_deps import sdl2, glew #Additional part ①
block_cipher = None
a = Analysis(['***.py'],
pathex=['c:\\Packaged directory'],
binaries=[],
datas=[],
hiddenimports=[]
hookspath=[],
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)], #Additional part ②
name='main',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True )
#Additional part ③
coll = COLLECT(exe, Tree('c:\\kivy file directory'),
a.binaries,
a.zipfiles,
a.datas,
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
strip=False,
upx=True,
name='main')
In my case, I created a folder (folder such as Layout) for ***. Kv in the same directory as the python file and put it in it. (It may not make much sense, but don't pick up unnecessary things in the collect process)
The main folder is created in the following directory, and a new exe file is created in it. All the files of the dependency exist in this, and when distributing the application, each main folder You will need it. (I think it can be more unified. This is the limit for me now.) If you can hide it in a directory somewhere and use only the shortcut of the exe file well I compromised because I thought it would be like that.
dist
|_main #← New exe file in this
|_***.exe
In particular, I used matplotlib == 3.1.1, but I found some information that could not be done with the latest version.
For the time being, GUI applications can now be distributed.
Recommended Posts