# Delay import _tkinter until we have set TCL_LIBRARY,# so that Tcl_FindExecutable has a chance to locate its# encoding directory.# Unfortunately, we cannot know the TCL_LIBRARY directory# if we don't know the tcl version, which we cannot find out# without import Tcl. Fortunately, Tcl will itself look in# <TCL_LIBRARY>\..\tcl<TCL_VERSION>, so anything close to# the real Tcl library will do.prefix=os.path.join(sys.prefix,"tcl")# if this does not exist, no further search is neededifos.path.exists(prefix):ifnotos.environ.has_key("TCL_LIBRARY"):fornameinos.listdir(prefix):ifname.startswith("tcl"):tcldir=os.path.join(prefix,name)ifos.path.isdir(tcldir):os.environ["TCL_LIBRARY"]=tcldir# Now set the other variables accordinglyimport_tkinterver=str(_tkinter.TCL_VERSION)fortin"tk","tix":key=t.upper()+"_LIBRARY"try:v=os.environ[key]exceptKeyError:v=os.path.join(sys.prefix,"tcl",t+ver)ifos.path.exists(os.path.join(v,"tclIndex")):os.environ[key]=v