我有一个复杂的Python
项目,我必须创建一个独立的可执行文件(*.exe
)。
我使用Pyinstaller
。
我已经解决了所有依赖项(Python软件包,DLL,SDK等),Pyinstaller
成功完成了exe
的创建。
但是当我想运行生成的exe
文件时,我会弹出一个错误消息,仅此而已。
我的项目树:
>>> tree /F
C:.
│ custom_logger.py
│ file_handler.py
│ generate_pdf_from_source.py
│ gui.py
│ gui.spec
│ info_img.png
│ init_tool.bat
│ main.py
│ README.txt
│ real_time_plotter.py
│ report_generation.py
│ start_thermal_cam_tool.vbs
│ utils.py
│ visualization.py
│ __init__.py
│
└───logs
file_handler.log
我的项目使用根文件夹中的文件,并使用logs
文件夹保存生成的日志文件。脚本不使用其他文件夹(我已经从树上删除了它们),仅使用管理文件夹/内容。
使用过的Pyinstaller
命令:
pyinstaller.exe -Fw --clean gui.spec
命令日志的最后一行:
147702 INFO: Looking for dynamic libraries
150141 INFO: Looking for eggs
150141 INFO: Using Python library c:\users\milan\appdata\local\programs\python\python37\python37.dll
150141 INFO: Found binding redirects:
[]
150171 INFO: Warnings written to C:\Users\milan\Desktop\thermal_cam\build\gui\warn-gui.txt
150764 INFO: Graph cross-reference written to C:\Users\milan\Desktop\thermal_cam\build\gui\xref-gui.html
151235 INFO: Appending 'datas' from .spec
151315 INFO: checking PYZ
151315 INFO: Building PYZ because PYZ-00.toc is non existent
151327 INFO: Building PYZ (ZlibArchive) C:\Users\milan\Desktop\thermal_cam\build\gui\PYZ-00.pyz
157984 INFO: Building PYZ (ZlibArchive) C:\Users\milan\Desktop\thermal_cam\build\gui\PYZ-00.pyz completed successfully.
158139 INFO: checking PKG
158139 INFO: Building PKG because PKG-00.toc is non existent
158139 INFO: Building PKG (CArchive) PKG-00.pkg
225097 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
225347 INFO: Bootloader c:\users\milan\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\bootloader\Windows-64bit\runw.exe
225347 INFO: checking EXE
225347 INFO: Building EXE because EXE-00.toc is non existent
225347 INFO: Building EXE from EXE-00.toc
225347 INFO: Appending archive to EXE C:\Users\milan\Desktop\thermal_cam\dist\gui.exe
225673 INFO: Building EXE from EXE-00.toc completed successfully.
基于上述日志,生成成功(日志的其他部分没有错误/警告可见)。
gui.spec
文件的内容:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['gui.py'],
pathex=['C:\\Users\\milan\\Desktop\\thermal_cam'],
binaries=[],
datas=[('C:\\Users\\milan\\Desktop\\thermal_cam\\*.py', '.'), ('C:\\Users\\milan\\Desktop\\thermal_cam\\*.png', '.')],
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,
[],
name='gui',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False )
遇到错误:
使用的设置:
其他信息:
我曾尝试在Python虚拟环境中制作exe
文件,但无法解决我的问题。
当我从-w
命令中删除Pyinstaller
选项并从CMD运行exe
文件时,我也看不到任何东西。我回来的提示就是这样。
我的问题:
当然,如何使exe
文件起作用?
为什么会出现该错误?
为什么在控制台/弹出窗口中找不到关于错误的更多详细信息?
答案 0 :(得分:0)
我发现了问题。 return bar == null ? false : FUBAR.equals(bar.getFoo());
文件夹尚未位于logs
文件旁边,并且脚本没有找到它。如果我手动创建它,则可执行文件可以正常工作。此外,如果找不到.exe
文件夹,则我更改了记录器模块,脚本将创建一个。通过此代码更改,我设法从我的logs
代码创建了一个完全独立的可执行文件。
使用Python
中的Tree
类的更优雅的解决方案。详细信息:https://pythonhosted.org/PyInstaller/advanced-topics.html#the-tree-class
但是,我仍然感到困惑,为什么我没有收到PyInstaller
错误!正如我提到的,我尝试过使用带有和不带有no such file or directory
选项的情况,但是没有出现任何错误...