【发布时间】:2021-10-27 12:13:30
【问题描述】:
我正在尝试使用 pyinstaller 将我的项目打包成可执行文件。我的程序 main.py 应该在我运行 exe 文件时运行。 Exe,因为程序必须以某种方式运行,而无需用户(无论如何都不是开发人员)需要安装模块和 python 本身。如果有更好/更简单的方法,请告诉我。
我使用 pip install tkinterdnd2 安装了 tkinterdnd2。
不确定这是否有必要,但这是程序的目录:(png仅用于我的程序,我不认为这是罪魁祸首):
Folder
- cardiologist.png
- img.png
.
. # a couple more pngs
.
- main.py
- patients' data csv.csv
- patients' data xlsx test.xlsx
- sample.xlsx
- sun-valley.tcl #this file and the 'theme' folder below are for my program's theme, also don't think these are the culprit
- theme
- dark
- a lot of pngs...
- dark.tcl
- light
- a lot of pngs...
- light.tcl
Pyinstaller 按预期创建了 2 个文件,build 和 dist。
build
- main
- base_library.zip
- certifi
- IPython
- jedi
- (some other files)
.
. a lot of .dylib files
.
- main # exe file to execute to run program
- matplotlib (this and next 4 are folders)
- numpy
- pandas
- parso
- PIL
- Python # exe file, don't know what this was created for
- (some more folders)
- tcl (this and next 2 are folders)
- tcl8
- 8.4
- platform
- .tm file
- .tm file
- 8.5
- 2 .tm files
- 8.6
- .tm file
- tdbc
- .tm file
- tkdnd2.8 (tried renaming to just tkdnd but same error)
- tk
- ttkwidgets
- 2 other folders
我使用的命令:
python -m PyInstaller main.py. # without python -m, 'command not found error' would happen
运行生成的exe时出错:
Traceback (most recent call last):
File "tkinterdnd2/TkinterDnD.py", line 53, in _require
_tkinter.TclError: can't find package tkdnd
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 16, in <module>
File "tkinterdnd2/TkinterDnD.py", line 285, in __init__
File "tkinterdnd2/TkinterDnD.py", line 55, in _require
RuntimeError: Unable to load tkdnd library.
[7015] Failed to execute script 'main' due to unhandled exception!
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
我已经上网并尝试寻找答案,但它们要么对我不起作用,要么像这样不够清楚:*.py script with tkinterdnd2 module doesn`t compile to an executable file(这个解决方案仍然给了我同样的错误)。
我也尝试过使用其他模块进行打包,例如 cx_freeze 和 py2app,但都产生了不同的错误,所以我现在回到 pyinstaller。我在 macOS 上。
有什么办法可以解决这个错误?
编辑
也尝试了python -m PyInstaller --clean -y -n "output_name" --add-data="tkdnd:tkdnd" main.py,但运行时产生了同样的错误。
【问题讨论】:
-
尝试直接从github上使用库github.com/petasis/tkdnd/tree/master/library
-
既然您安装了
tkinterdnd2,您是否在配置文件中尝试过- tkinterdnd2? -
@PetrL。刚刚尝试从那里下载整个 zip,将整个文件夹放入 tcl 8.6,甚至将其重命名为
tkdnd,仍然会弹出相同的错误。将它放在与 main 相同的目录中也会产生相同的错误。 -
@BryanOakley 我可以知道你在说什么配置文件吗?
标签: python tkinter pyinstaller exe