Install python with custom tk-tcl installation
Derek Thomas
derekathomas at gmail.com
Mon Dec 17 22:47:46 EST 2012
Hello,
I seem to have a problem because it seems Tkinter assumes relative paths for TCL_LIBRARY and TK_LIBRARY.
I am working with the homebrew group to get python27 to install nicely with a custom installation of tk and tcl (https://github.com/mxcl/homebrew/pull/16626). However, this breaks because homebrew installs tk and tcl in separate directories and then soft-links them to /usr/local/lib. When I install python with this method, it breaks tkinter with the following error:
```
>>> import Tkinter; root = Tkinter.Tk()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py",
line 1685, 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:
/usr/local/Cellar/tcl/8.5.9/lib/tcl8.5/tk8.5
/usr/local/Cellar/tcl/8.5.9/lib/tcl8.5/tk8.5/Resources/Scripts
/usr/local/Cellar/tcl/8.5.9/lib/tk8.5
/usr/local/Cellar/tcl/8.5.9/lib/tk8.5/Resources/Scripts
/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/lib/tk8.5
/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/lib/tk8.5/Resources/Scripts
/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/lib/tk8.5
/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/library
This probably means that tk wasn't installed properly.
```
It is looking in the wrong library directory for the tk.tcl file, which is in /usr/local/Cellar/tk/8.5.9/lib/tk8.5/tk.tcl . In fact, it is assuming that the tk8.5 lib-directory is installed relative to the tcl8.5 lib-directory which is incorrect. It fails because it cannot find the file in the relative directory.
I can fix this by setting the environment variable TCL_LIBRARY to a path that is relative to a soft-linked tk-library (/usr/local/lib/tcl8.5), but is there someway to set tkinter to search the correct path during installation without having to set the environment after installation? I looked in _tkinter.c and tkappinit.c but could not find where it was determining the tcl library.
If you have any advice or thoughts, I would be very appreciative. Thank you in advance.
More information about the Python-list
mailing list