1

I made an app that uses tkinter and tkinterdnd moudles. It works completely fine when I launch it as a script, however when I try to make and executable file from it and laucnh it, foloowing error ocures:

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 "IxcomGUI.py", line 128, in <module>
  File "IxcomGUI.py", line 11, in __init__
  File "TkinterDnD2\TkinterDnD.py", line 285, in __init__
  File "TkinterDnD2\TkinterDnD.py", line 55, in _require
RuntimeError: Unable to load tkdnd library.
[14512] Failed to execute script 'IxcomGUI' due to unhandled exception!

I tried following:

  1. Installed tkinterdnd2 with pip install and built with pyinstaller myscript.py.
  2. Manually installed tkinterdnd2 module as shown in this video https://www.youtube.com/watch?v=JIy0QjwQBl0&t=605s&ab_channel=RamonWilliams and built with pyinstaller myscript.py
  3. Repeated previous step, but added this thing https://github.com/pmgagne/tkinterdnd2/blob/master/hook-tkinterdnd2.py
  4. Tried to implicitly tell pyinstaller path to tkdnd module with specifying path to the module with --paths flag.

All this attempts led to error bellow. Does anyone know some kind of solution?

HappyLemon
  • 78
  • 7

3 Answers3

3

The issue here is that Drag n Drop requires two components: the TCL libraries and the Tkinter interface to them. I install both manually to config my environment. (See my answer to How to Install and Use TkDnD with Python Tkinter on OSX?). I know someone packaged something on PyPI for the TkinterDnD2, but I haven't looked into it.

I have a project which uses TkinterDnD2. I build it with PyInstaller and see the same error you see (more or less). Running PyInstaller with the --onedir option (rather than the --onefile option), I saw that tkdnd2.8 was missing from my dist directory.

To rectify this, on Windows, I added

--add-binary "C:/Python/Python38-32/tcl/tkdnd2.8;tkdnd2.8"

to the PyInstaller command line, and that did the trick. I can now build a --onefile executable, and it runs without error.

GaryMBloom
  • 5,350
  • 1
  • 24
  • 32
0

Apparently it was unnexpectedly easy to fix this issue. All you need to is to get to the <YourPath>\Python39\tcl directory and find tkdnd2.8 directory, and move it to the tcl8.6 directory. I have also renamed it to just tkdnd, however I don't know whether it's necessary.

Here is the original link that saved my day: http://pyinstaller.47505.x6.nabble.com/tkinter-TclError-can-t-find-package-tkdnd-td2330.html

TheLizzard
  • 7,248
  • 2
  • 11
  • 31
HappyLemon
  • 78
  • 7
  • I am also facing issue but I can successdully build and make one executable file by pyinstaller but when I try to launch i get the below error: RuntimeError: Unable to load tkdnd library. I just checked my tcl directory doesn't have tkdnd folder, please suggest me on this issue. Thanks – Sagar H Sep 09 '21 at 08:11
  • Uh, I haven`t worked on this project for a while tbh, but maybe your libraries are installed in some other directory? – HappyLemon Sep 10 '21 at 14:50
  • 2
    The above link doesn't work anymore. Here I've found the archive: https://www.mail-archive.com/pyinstaller@googlegroups.com/msg07800.html – deshu Sep 27 '21 at 12:25
0

I'm using tkinterdnd2 installed from pip, and not TkinterDnD.

What really worked for me was this flag:

 --add-data "C:/Users/myName/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0/LocalCache/local-packages/Python39/site-packages/tkinterdnd2;tkinterdnd2"

It expects tkdnd to be a folder inside tkinterdnd2. Just using additional-hooks/hidden import on tkinterdnd2 and tkdnd did now preserve that subfolder structure.

Ricardo Guerreiro
  • 497
  • 1
  • 4
  • 17