*.py script with tkinterdnd2 module doesn`t compile to an executable file

Question:

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 "TkinterDnD2TkinterDnD.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 "TkinterDnD2TkinterDnD.py", line 285, in __init__
  File "TkinterDnD2TkinterDnD.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?

Asked By: HappyLemon

||

Answers:

Apparently it was unnexpectedly easy to fix this issue. All you need to is to get to the <YourPath>Python39tcl 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

Answered By: HappyLemon

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.

Answered By: GaryMBloom

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.

Answered By: Ricardo Guerreiro
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.