summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2002-02-24 16:51:45 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2002-02-24 16:51:45 (GMT)
commit4ca196dd8de944c129db44063310ccfdf9037a7a (patch)
tree66ab8f49ea6895ca2b5ebb7b43b67e991b6376b5
parenta82d3470ec74997947bbd81a894825082ed0b2d1 (diff)
downloadcpython-4ca196dd8de944c129db44063310ccfdf9037a7a.zip
cpython-4ca196dd8de944c129db44063310ccfdf9037a7a.tar.gz
cpython-4ca196dd8de944c129db44063310ccfdf9037a7a.tar.bz2
Set TCL_LIBRARY before import _tkinter. Suggested by Kirill Simonov.
Fixes #418173 and #219960. 2.2.1 candidate.
-rw-r--r--Lib/lib-tk/FixTk.py41
1 files changed, 31 insertions, 10 deletions
diff --git a/Lib/lib-tk/FixTk.py b/Lib/lib-tk/FixTk.py
index 029e7cd..765e639 100644
--- a/Lib/lib-tk/FixTk.py
+++ b/Lib/lib-tk/FixTk.py
@@ -1,11 +1,32 @@
-import sys, os, _tkinter
+import sys, os
-ver = str(_tkinter.TCL_VERSION)
-for t in "tcl", "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
+# 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 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