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?

2
  • Did you include the --additional-hooks-dir=. part in your pyinstaller command line, like the file in step 3 said to do? Commented Aug 8, 2021 at 15:54
  • yes I did, but I`ve also found a sollution by an accident, I already posted it here. Commented Aug 8, 2021 at 15:56

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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

3 Comments

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
Uh, I haven`t worked on this project for a while tbh, but maybe your libraries are installed in some other directory?
The above link doesn't work anymore. Here I've found the archive: mail-archive.com/[email protected]/msg07800.html
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.