Set TCL_LIBRARY before import _tkinter. Suggested by Kirill Simonov.

Fixes #418173 and #219960. 2.2.1 candidate.
This commit is contained in:
Martin v. Löwis 2002-02-24 16:51:45 +00:00
parent a82d3470ec
commit 4ca196dd8d
1 changed files with 31 additions and 10 deletions

View File

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