[英]Pyinstaller generated EXE file does not work
我有一個復雜的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
文件,但它沒有解決我的問題。
當我從我的Pyinstaller
命令中刪除-w
選項並從 CMD 運行exe
文件時,我也沒有看到任何東西。 我得到提示,僅此而已。
我的問題:
當然,如何使exe
文件工作?
為什么我會收到該錯誤?
為什么我沒有在控制台/彈出窗口中獲得有關錯誤的更多詳細信息?
我發現了問題。 logs
文件夾不在.exe
文件旁邊,腳本沒有找到它。 如果我手動創建它,可執行文件可以正常工作。 此外,如果找不到logs
文件夾,我會更改我的記錄器模塊,腳本會創建一個。 通過此代碼更改,我設法從我的Python
代碼創建了一個完全獨立的可執行文件。
使用PyInstaller
中的Tree
類的更優雅的解決方案。 詳情: https ://pythonhosted.org/PyInstaller/advanced-topics.html#the-tree-class
但是,我仍然很困惑為什么我沒有收到no such file or directory
錯誤! 正如我提到的,我已經嘗試過使用和不使用-w
選項,但我沒有收到任何錯誤...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.