运行 .exe 时脚本错误中未处理的异常

问题描述 投票:0回答:0

我是 Python 的新手,一直在使用它来完成一个项目,作为我的计算机科学 A-Level 的一部分。我的项目是一个带 GUI 的电子飞行包(我用过 appJar 模块)和各种功能,可以获取天气数据、航图等。

我最近尝试使用 Auto Py To Exe 将我的 .py 文件转换为 .exe 文件。当我运行 .exe 文件时,出现此错误:

Traceback (most recent call last):
  File "EFB.py", line 593, in <module>
    with app.subWindow("Login", title="Login", modal=True, blocking=False, transient=False, grouped=True):
  File "contextlib.py", line 119, in __enter__
  File "appJar\appjar.py", line 5668, in subWindow
  File "appJar\appjar.py", line 5695, in startSubWindow
  File "appJar\appjar.py", line 2905, in setIcon
  File "tkinter\__init__.py", line 2080, in wm_iconbitmap
_tkinter.TclError: bitmap "C:\Users\Maksim\AppData\Local\Temp\_MEI78242\appJar\resources\icons\favicon.ico" not defined

这是Auto Py To Exe运行的命令:

pyinstaller --noconfirm --onefile --windowed --add-data "C:/Users/Maksim/PycharmProjects/Electronic Flight Bag by Maksim Ferguson;Electronic Flight Bag by Maksim Ferguson/" --hidden-import "appJar"  "C:/Users/Maksim/PycharmProjects/Electronic Flight Bag by Maksim Ferguson/EFB.py"

这是 Auto Py To Exe 的输出:

Running auto-py-to-exe v2.30.0
Building directory: C:\Users\Maksim\AppData\Local\Temp\tmpyo3tatn3
Provided command: pyinstaller --noconfirm --onefile --windowed --add-data "C:/Users/Maksim/PycharmProjects/Electronic Flight Bag by Maksim Ferguson;Electronic Flight Bag by Maksim Ferguson/" --hidden-import "appJar"  "C:/Users/Maksim/PycharmProjects/Electronic Flight Bag by Maksim Ferguson/EFB.py"
Recursion Limit is set to 5000
Executing: pyinstaller --noconfirm --onefile --windowed --add-data C:/Users/Maksim/PycharmProjects/Electronic Flight Bag by Maksim Ferguson;Electronic Flight Bag by Maksim Ferguson/ --hidden-import appJar C:/Users/Maksim/PycharmProjects/Electronic Flight Bag by Maksim Ferguson/EFB.py --distpath C:\Users\Maksim\AppData\Local\Temp\tmpyo3tatn3\application --workpath C:\Users\Maksim\AppData\Local\Temp\tmpyo3tatn3\build --specpath C:\Users\Maksim\AppData\Local\Temp\tmpyo3tatn3

45019 INFO: PyInstaller: 5.8.0
45028 INFO: Python: 3.9.13
45051 INFO: Platform: Windows-10-10.0.19045-SP0
45058 INFO: wrote C:\Users\Maksim\AppData\Local\Temp\tmpyo3tatn3\EFB.spec
45074 INFO: UPX is not available.
45095 INFO: Extending PYTHONPATH with paths
['C:\\Users\\Maksim\\PycharmProjects\\Electronic Flight Bag by Maksim Ferguson']
45651 INFO: checking Analysis
45654 INFO: Building Analysis because Analysis-00.toc is non existent
45670 INFO: Initializing module dependency graph...
45687 INFO: Caching module graph hooks...
45712 INFO: Analyzing base_library.zip ...
46672 INFO: Loading module hook 'hook-encodings.py' from 'C:\\Users\\Maksim\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
47568 INFO: Loading module hook 'hook-pickle.py' from 'C:\\Users\\Maksim\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
48034 INFO: Loading module hook 'hook-heapq.py' from 'C:\\Users\\Maksim\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
48470 INFO: Caching module dependency graph...
48563 INFO: running Analysis Analysis-00.toc
48586 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by C:\Users\Maksim\AppData\Local\Programs\Python\Python39\python.exe
48624 INFO: Analyzing C:\Users\Maksim\PycharmProjects\Electronic Flight Bag by Maksim Ferguson\EFB.py
49307 INFO: Loading module hook 'hook-platform.py' from 'C:\\Users\\Maksim\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
49586 INFO: Loading module hook 'hook-idlelib.py' from 'C:\\Users\\Maksim\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
49763 INFO: Loading module hook 'hook-difflib.py' from 'C:\\Users\\Maksim\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
49968 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'C:\\Users\\Maksim\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
50073 INFO: Loading module hook 'hook-xml.py' from 'C:\\Users\\Maksim\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
51332 INFO: Loading module hook 'hook-sysconfig.py' from 'C:\\Users\\Maksim\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
51792 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'C:\\Users\\Maksim\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
51981 INFO: Processing pre-find module path hook distutils from 'C:\\Users\\Maksim\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
51999 INFO: Loading module hook 'hook-distutils.py' from 'C:\\Users\\Maksim\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
52097 INFO: Loading module hook 'hook-distutils.util.py' from 'C:\\Users\\Maksim\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
52208 INFO: Loading module hook 'hook-xml.dom.domreg.py' from 'C:\\Users\\Maksim\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
52380 INFO: Loading module hook 'hook-sqlite3.py' from 'C:\\Users\\Maksim\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
52684 INFO: Processing module hooks...
52701 INFO: Loading module hook 'hook-_tkinter.py' from 'C:\\Users\\Maksim\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
52708 INFO: checking Tree
52723 INFO: Building Tree because Tree-00.toc is non existent
52738 INFO: Building Tree Tree-00.toc
52839 INFO: checking Tree
52846 INFO: Building Tree because Tree-01.toc is non existent
52861 INFO: Building Tree Tree-01.toc
52883 INFO: checking Tree
52892 INFO: Building Tree because Tree-02.toc is non existent
52907 INFO: Building Tree Tree-02.toc
52941 INFO: Looking for ctypes DLLs
52967 INFO: Analyzing run-time hooks ...
52987 INFO: Including run-time hook 'C:\\Users\\Maksim\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgutil.py'
53002 INFO: Including run-time hook 'C:\\Users\\Maksim\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
53018 INFO: Including run-time hook 'C:\\Users\\Maksim\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth__tkinter.py'
53033 INFO: Including run-time hook 'C:\\Users\\Maksim\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py'
53062 INFO: Looking for dynamic libraries
53744 INFO: Looking for eggs
53753 INFO: Using Python library C:\Users\Maksim\AppData\Local\Programs\Python\Python39\python39.dll
53768 INFO: Found binding redirects: 
[]
53786 INFO: Warnings written to C:\Users\Maksim\AppData\Local\Temp\tmpyo3tatn3\build\EFB\warn-EFB.txt
53837 INFO: Graph cross-reference written to C:\Users\Maksim\AppData\Local\Temp\tmpyo3tatn3\build\EFB\xref-EFB.html
53870 INFO: Appending 'datas' from .spec
54026 INFO: checking PYZ
54028 INFO: Building PYZ because PYZ-00.toc is non existent
54037 INFO: Building PYZ (ZlibArchive) C:\Users\Maksim\AppData\Local\Temp\tmpyo3tatn3\build\EFB\PYZ-00.pyz
54486 INFO: Building PYZ (ZlibArchive) C:\Users\Maksim\AppData\Local\Temp\tmpyo3tatn3\build\EFB\PYZ-00.pyz completed successfully.
54504 INFO: checking PKG
54513 INFO: Building PKG because PKG-00.toc is non existent
54529 INFO: Building PKG (CArchive) EFB.pkg
62442 INFO: Building PKG (CArchive) EFB.pkg completed successfully.
62562 INFO: Bootloader C:\Users\Maksim\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\bootloader\Windows-64bit-intel\runw.exe
62581 INFO: checking EXE
62596 INFO: Building EXE because EXE-00.toc is non existent
62612 INFO: Building EXE from EXE-00.toc
62628 INFO: Copying bootloader EXE to C:\Users\Maksim\AppData\Local\Temp\tmpyo3tatn3\application\EFB.exe.notanexecutable
62689 INFO: Copying icon to EXE
62705 INFO: Copying icons from ['C:\\Users\\Maksim\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\bootloader\\images\\icon-windowed.ico']
62764 INFO: Writing RT_GROUP_ICON 0 resource with 104 bytes
62782 INFO: Writing RT_ICON 1 resource with 3752 bytes
62798 INFO: Writing RT_ICON 2 resource with 2216 bytes
62814 INFO: Writing RT_ICON 3 resource with 1384 bytes
62829 INFO: Writing RT_ICON 4 resource with 38188 bytes
62845 INFO: Writing RT_ICON 5 resource with 9640 bytes
62861 INFO: Writing RT_ICON 6 resource with 4264 bytes
62876 INFO: Writing RT_ICON 7 resource with 1128 bytes
62893 INFO: Copying 0 resources to EXE
62907 INFO: Embedding manifest in EXE
62923 INFO: Updating manifest in C:\Users\Maksim\AppData\Local\Temp\tmpyo3tatn3\application\EFB.exe.notanexecutable
62984 INFO: Updating resource type 24 name 1 language 0
63003 INFO: Appending PKG archive to EXE
63043 INFO: Fixing EXE headers
63481 INFO: Building EXE from EXE-00.toc completed successfully.

Moving project to: C:\Users\Maksim\PycharmProjects\Electronic Flight Bag by Maksim Ferguson

我不确定这到底是什么意思,任何帮助将不胜感激。

我之前在 .py 代码中使用相对路径并将其转换为 .exe 时遇到过问题。所以我使用了经过研究后发现的这个功能:

def ResourcePath(relative_path):
    # Gets absolute path to resource
    try:
        base_path = sys._MEIPASS
    except Exception:
        base_path = os.path.abspath(".")

    return os.path.join(base_path, relative_path)

我不确定是否会导致错误?

对不起听起来死了nooby :)

python pyinstaller exe auto-py-to-exe appjar
© www.soinside.com 2019 - 2024. All rights reserved.