使用 Pyinstaller 制作 exe 文件时出现问题(使用 tkinter 和 Custom tkinter 制作的文件)

Muh*_*hir 3 python tkinter pyinstaller customtkinter

我正在尝试使用 tkinter 和自定义 tkinter 制作一个用于数据输入的小型应用程序。代码在 python 中运行良好,我使用 pyinstaller --onefile --noconsole try45.py 制作了它的 exe 文件

但在运行 exe 文件时,它会给出标记为“脚本中未处理的异常”的错误。其详细信息附如下,

I have also attached the image of the error. The first two lines of it say "Failed to execute script 'try45' due to unhandled exception: [Errno 2] No such file or directory: 'C:\Users\Farzan Bashir\AppData\Local\Temp\_MEI127522\customtkinter\assets\themes\blue.json"

and the details in next lines are,

Traceback (most recent call last): File "try45.py", line 2, in File "", line 1027, in _find_and_load File "", line 1006, in _find_and_load_unlocked File "", line 688, in load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "customtkinter_init.py", line 3, in File "", line 1027, in _find_and_load File "", line 1006, in _find_and_load_unlocked File "", line 688, in _load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "customtkinter\widgets\customtkinter_input_dialog.py", line 4, in File "", line 1027, in _find_and_load File "", line 1006, in _find_and_load_unlocked File "", line 688, in _load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "customtkinter\widgets\customtkinter_label.py", line 4, in File "", line 1027, in _find_and_load File "", line 1006, in _find_and_load_unlocked File "", line 688, in _load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "customtkinter\widgets\customtkinter_tk.py", line 9, in File "", line 1027, in _find_and_load File "", line 1006, in _find_and_load_unlocked File "", line 688, in _load_unlocked File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "customtkinter\customtkinter_theme_manager.py", line 83, in File "customtkinter\customtkinter_theme_manager.py", line 16, in load_theme FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\Farzan Bashir\AppData\Local\Temp\_MEI44122\customtkinter\assets\themes\blue.json'

PLEASE HELP !!!

小智 5

遇到了同样的问题,将 site-packages 文件夹中的自定义 tkinter 文件夹数据添加到控制台命令中解决了它,在这里:

pyinstaller --noconfirm --onefile --windowed --add-data "C:\Users\(your pc name)\AppData\Local\Programs\Python\(your python version that has custom tkinter)\Lib\site-packages\customtkinter;customtkinter/"  "<Path to Python Script>"
Run Code Online (Sandbox Code Playgroud)