我正在尝试从一个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')


我不确定我需要在遵循示例re的.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部分实现的吗?
发布于 2020-08-05 04:09:55
我将python目录中的所有包复制到主目录(即.exe和.py的位置等),在我的示例中是face_recognition库。
https://stackoverflow.com/questions/63141989
复制相似问题