PyInstaller 和 Kivy 构建但不构建 运行
PyInstaller and Kivy builds but doesn't run
我正在尝试从一个 kivy 项目创建一个 windows .exe。我遵循了 PyInstaller https://kivy.org/doc/stable/guide/packaging-windows.html 的指南
我能够按照命令构建应用程序,编辑规范文件并使用它来编译 .exe
所有目录都已创建并且没有发生错误,但是,当我 运行 应用程序 .exe 时,它会启动命令提示符,然后再次关闭。
这是我第一次使用 Pyinstaller 和 kivy,所以我希望我只是遗漏了一些简单的东西。
# -*- 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')
我不确定我需要在 .spec 文件中包含哪些 kivy 依赖项我已经按照示例回复:sdl2、glew 等...
有没有办法在我 运行 尝试解决错误时跟踪 .exe?
(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.
我有 运行 建议的 .exe,face_recognition 导入似乎有问题。
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
如何包含 face_recognition 包?这是通过 .spec Collect 部分实现的吗?
我将所有包从 python 目录复制到主目录(即 .exe 和 .py 等的位置)在我的例子中这是 face_recognition 库。
我正在尝试从一个 kivy 项目创建一个 windows .exe。我遵循了 PyInstaller https://kivy.org/doc/stable/guide/packaging-windows.html 的指南 我能够按照命令构建应用程序,编辑规范文件并使用它来编译 .exe 所有目录都已创建并且没有发生错误,但是,当我 运行 应用程序 .exe 时,它会启动命令提示符,然后再次关闭。 这是我第一次使用 Pyinstaller 和 kivy,所以我希望我只是遗漏了一些简单的东西。
# -*- 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')
我不确定我需要在 .spec 文件中包含哪些 kivy 依赖项我已经按照示例回复:sdl2、glew 等... 有没有办法在我 运行 尝试解决错误时跟踪 .exe?
(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.
我有 运行 建议的 .exe,face_recognition 导入似乎有问题。
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
如何包含 face_recognition 包?这是通过 .spec Collect 部分实现的吗?
我将所有包从 python 目录复制到主目录(即 .exe 和 .py 等的位置)在我的例子中这是 face_recognition 库。