I am trying to create a windows .exe from a kivy project. I have followed the guide from PyInstaller https://kivy.org/doc/stable/guide/packaging-windows.html I am able to build the app following the commands, edit the spec file and use it to compile the .exe All of the directories are created and no errors occur however, when I run the application .exe it launches a command prompt and then closes again. This is my first time utilising Pyinstaller and kivy so Im hoping I am just missing something simple.
# -*- mode: python ; coding: utf-8 -*-
from kivy_deps import sdl2, glew
block_cipher = None
a = Analysis(['C:\\Users\\thoma\\PycharmProjects\\FacesGUI\\main.py'],
pathex=['C:\\Users\\thoma\\PycharmProjects\\FacesGUI\\exe'],
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,
[],
exclude_binaries=True,
name='FacesGUI',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe, Tree('C:\\Users\\thoma\\PycharmProjects\\FacesGUI\\'),
a.binaries,
a.zipfiles,
a.datas,
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
strip=False,
upx=True,
upx_exclude=[],
name='FacesGUI')
I am uncertain what kivy dependencies I need to include in the .spec file I have followed the example re: sdl2, glew etc... Is there a way to trace the .exe when I run it to try troubleshoot the error?
(venv) C:\Users\thoma\PycharmProjects\FacesGUI\exe>python -m PyInstaller FacesGUI.spec
78 INFO: PyInstaller: 3.6
78 INFO: Python: 3.7.1
78 INFO: Platform: Windows-10-10.0.18362-SP0
78 INFO: UPX is not available.
93 INFO: Extending PYTHONPATH with paths
['C:\\Users\\thoma\\PycharmProjects\\FacesGUI',
'C:\\Users\\thoma\\PycharmProjects\\FacesGUI\\exe']
93 INFO: checking Analysis
200 INFO: checking PYZ
263 INFO: checking PKG
263 INFO: Building because C:\Users\thoma\PycharmProjects\FacesGUI\exe\build\FacesGUI\FacesGUI.exe.manifest changed
263 INFO: Building PKG (CArchive) PKG-00.pkg
300 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
300 INFO: Bootloader C:\Users\thoma\PycharmProjects\FacesApp\venv\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
300 INFO: checking EXE
300 INFO: Rebuilding EXE-00.toc because pkg is more recent
300 INFO: Building EXE from EXE-00.toc
300 INFO: Appending archive to EXE C:\Users\thoma\PycharmProjects\FacesGUI\exe\build\FacesGUI\FacesGUI.exe
300 INFO: Building EXE from EXE-00.toc completed successfully.
316 INFO: checking Tree
347 INFO: Building Tree-00.toc because directory C:\Users\thoma\PycharmProjects\FacesGUI\exe\build\FacesGUI changed
347 INFO: Building Tree Tree-00.toc
401 INFO: checking Tree
401 INFO: checking Tree
401 INFO: checking COLLECT
WARNING: The output directory "C:\Users\thoma\PycharmProjects\FacesGUI\exe\dist\FacesGUI" and ALL ITS CONTENTS will be REMOVED!
Continue? (y/N)y
On your own risk, you can use the option `--noconfirm` to get rid of this question.
2500 INFO: Removing dir C:\Users\thoma\PycharmProjects\FacesGUI\exe\dist\FacesGUI
2638 INFO: Building COLLECT COLLECT-00.toc
5947 INFO: Building COLLECT COLLECT-00.toc completed successfully.
I have run the .exe as suggested and it appears there is an issue with the face_recognition import.
C:\Users\thoma\PycharmProjects\FacesGUI\exe\dist\FacesGUI>FacesGUI.exe
Traceback (most recent call last):
File "main.py", line 12, in <module>
import face_recognition
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "c:\users\thoma\pycharmprojects\facesapp\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\face_recognition\__init__.py", line 7, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "c:\users\thoma\pycharmprojects\facesapp\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\face_recognition\api.py", line 20, in <module>
RuntimeError: Unable to open C:\Users\thoma\PycharmProjects\FacesGUI\exe\dist\FacesGUI\face_recognition_models\models\shape_predictor_68_face_landmarks.dat
[4960] Failed to execute script main
How do I include the face_recognition package? is this achieved through the .spec Collect section?
I copied all of the packages from the python directory into the main directory (i.e. the location of the .exe and .py etc) in my case this was the face_recognition libraries.