dplusplus <notfakeusern...@gmail.com> added the comment:

Revisited this recently and found a fix. This problem seems to appear only if 
Tcl and/or Tk is installed in a non-standard folder.

In the ./configure call, include `-ltcl8.6 -ltk8.6` (for Tcl/Tk 8.6.x) in the 
--with-tcltk-libs specification, so the command looks like `./configure 
--with-tcltk-libs='-L/path/to/tcl/lib/location -L/path/to/tk/lib/location 
-ltcl8.6 -ltk8.6'`. Since the Tcl and Tk shared libraries are in non-standard 
locations, set LD_LIBRARY or append '-Wl,-rpath,/path/to/tcl/lib/location 
-Wl,-rpath,/path/to/tk/lib/location' to --with-tcltk-libs. Run make and the 
tkinter import failure is no longer there.


`import tkinter` runs fine, but an error appears when running the simple hello 
world script at https://docs.python.org/3.6/library/tkinter.html:

Traceback (most recent call last):
  File "/opt/tk_sample.py", line 22, in <module>
    root = tk.Tk()
  File "/opt/Python-3.6.5/Lib/tkinter/__init__.py", line 2020, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, 
wantobjects, useTk, sync, use)
_tkinter.TclError: Can't find a usable tk.tcl in the following directories:
    /opt/tk/lib /opt/tcl/lib/tcl8.6/tk8.6 /opt/tcl/lib/tk8.6 
/opt/Python-3.6.5/lib/tk8.6 /opt/Python-3.6.5/lib/tk8.6 /opt/lib/tk8.6 
/opt/Python-3.6.5/library

`tk.tcl` is in /opt/tk/lib/tk8.6; looking at the directories listed in the 
error message _tkinter is expecting Tcl and Tk to be installed in the same 
folder (To be fair, Tk warns about this in its configure script).
This is fixed by setting the environment variable TK_LIBRARY to the folder 
where tk.tcl is. I do not consider this a complete solution though, since 
TK_LIBRARY needs to be set to run anything that uses tkinter.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31817>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to