我正在尝试使用pyinstaller将我的项目打包到一个可执行文件中。当我运行main.py文件时,我的程序应该运行。Exe,因为程序必须在没有用户的情况下运行,用户不是开发人员,需要安装模块和python本身。如果有更好/更简单的方法,请告诉我。
我通过使用tkinterdnd2安装了pip install tkinterdnd2。
不确定这是否必要,但这是程序的目录:( pngs仅用于我的程序,我不认为这是罪魁祸首):
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.tclPyinstaller按预期创建了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模块的tkinterdnd2脚本不能编译成可执行文件 (这个解决方案仍然给了我同样的错误)。
我也尝试过使用其他模块来打包,比如cx_freeze和py2app,但是两者都产生了不同的错误,所以我现在回到了pyinstaller。我上macOS了。
有办法纠正这个错误吗?
编辑
也尝试了python -m PyInstaller --clean -y -n "output_name" --add-data="tkdnd:tkdnd" main.py,但是在运行时产生了相同的错误。
发布于 2021-12-29 23:24:03
我终于让它不需要手动移动文件夹就能工作。
pip install tkinterdnd2我用auto py来执行,它不适用于“--添加-二进制”,所以我在gui中使用了“add-文件夹”,这基本上就是“--add”。
pyinstaller --noconfirm --onefile --windowed --add-data "<python_path>/Lib/site-packages/tkinterdnd2;tkinterdnd2/" "<your_script>"发布于 2021-12-07 20:24:46
这里的问题是拖n拖放需要两个组件: TCL库和Tkinter接口。我手动安装这两种配置我的环境。(见我对如何在OSX上安装和使用的TkDnD?的回答)。我知道有人在PyPI上为TkinterDnD2打包了一些东西,但我还没有对它进行调查。
我有一个使用TkinterDnD2的项目。我用PyInstaller构建它,并看到与您看到的相同的错误(或多或少)。使用--onedir选项(而不是--onefile选项)运行PyInstaller时,我发现tkdnd2.8在我的dist目录中丢失了。
为了纠正这个问题,在Windows上,我添加了
--add-binary "C:/Python/Python38-32/tcl/tkdnd2.8;tkdnd2.8"到PyInstaller命令行,这就成功了。我现在可以构建一个-onefile可执行文件,并且它没有错误地运行。
你也尝试过类似的方法,但是我使用了--加法二进制而不是--添加数据,我给出了库的完整路径。
发布于 2021-12-30 21:43:54
我不确定其他答案的第一手经验,但我个人在我的应用程序中分发tkdnd。当然,我第一次这样做是在tkinterdnd2在PyPi中可用之前。我使用了tkdnd发行版和python包装器。在我的构建脚本中,我
copy_tree('build_files/tkdnd2.9.2', os.path.dirname(sys.executable) + '/tcl/tkdnd2.9.2')
copy_tree('build_files/TkinterDnD2', os.path.dirname(sys.executable) + '/Lib/site-packages/TkinterDnD2')在我的规范文件里,
tkdnd = [(os.path.abspath(file), 'tkdnd2.9.2') for file in iglob('build_files/tkdnd2.9.2/*.*')]
data_files = [...] + tkdnd
a = Analysis9(..., datas=data_files,...)您可以进一步查看我的项目,音乐施法者
https://stackoverflow.com/questions/68955373
复制相似问题