繁体   English   中英

Pyinstaller 生成的 EXE 文件不起作用

[英]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 )

获取错误:

我收到错误

使用的设置:

  • 安装程序:3.5
  • 蟒蛇:3.7.5
  • 平台:Windows-10-10.0.18362-SP0

附加信息:

我试图在 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM