Included Python library problem

I am attempting to do some Python scripting for the Netlist and/or Bom tool in Eeschema but have run into an issue. I am curious if anyone else has run into the same problem.

My script imports Tkinter for a simple GUI. The module imports fine in my normal Python2.7 dev environment, but when I try to run the script inside of Eeschema it throws an error.

 Error messages:
   Traceback (most recent call last):
  File "C:/Users/username/Documents//interface.py", line 2, in <module>
    import Tkinter
  File "C:\Program Files\KiCad\lib\python2.7\lib-tk/Tkinter.py", line 39, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ImportError: DLL load failed: The specified module could not be found.

Is it something I’m doing, or is it how Python gets packed with KiCad?
I am using stable 4.0.7 on Win10.

Any help would be greatly appreciated. Thanks in advance.

I didn’t realise eeschema has a Python console, do you mean pcbnew?

Anyway, KiCad has its own installation of Python so you would need to install tkinter into it separately to your normal Python2.7.

You can run python scripts from the Netlist and BOM tools in eeschema. Scripts such as KiBom for generating formatted BOMs.

And Tkinter is part of the standard Library in Python2.7, the Tkinter module is found, it just fails to initialize when I use the KiCad python install.

Oh sorry, BOM tools. I tried a trivial test, it seemed to work ok.

Edit: I tried a less trivial test, and it failed in KiCad, ok at command line.

Error messages:
Traceback (most recent call last):
  File "C:/temp2/tk_test.py", line 16, in <module>
    app = Application()
  File "C:/temp2/tk_test.py", line 6, in __init__
    tk.Frame.__init__(self, master)
  File "C:\Programs\KiCad\lib\python2.7\lib-tk/Tkinter.py", line 2575, in __init__
    Widget.__init__(self, master, 'frame', cnf, {}, extra)
  File "C:\Programs\KiCad\lib\python2.7\lib-tk/Tkinter.py", line 2087, in __init__
    BaseWidget._setup(self, master, cnf)
  File "C:\Programs\KiCad\lib\python2.7\lib-tk/Tkinter.py", line 2062, in _setup
    _default_root = Tk()
  File "C:\Programs\KiCad\lib\python2.7\lib-tk/Tkinter.py", line 1820, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: Can't find a usable init.tcl in the following directories: 
    {C:/Program Files/Git/lib/tcl8.6} C:/Programs/KiCad/lib/tcl8.6 C:/Programs/lib/tcl8.6 C:/Programs/KiCad/library C:/Programs/library C:/Programs/tcl8.6.6/library C:/tcl8.6.6/library



This probably means that Tcl wasn't installed properly.

Either way I think the error messages are telling us that the installation is not correct. I would raise a bug on the bug tracker.

1 Like

Thanks for trying it out. Bug raised.

It seems that _tkinter needs tcl86.dll and tk86.dll, both of which are missing from the KiCad install.

I’m not sure why there is a dependency on tcl, but it seems KiCad is also missing tcl.

Interesting, my standard python install directory does not have those dlls either, it has tcl85.dll and tk85.dll

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.