blob: 0726a51b92bf3f61987a5b2f9418155fb5ebd843 [file] [log] [blame]
Martin v. Löwis4ca196d2002-02-24 16:51:45 +00001import sys, os
Guido van Rossumea32cbb2001-10-12 15:34:29 +00002
Martin v. Löwis4ca196d2002-02-24 16:51:45 +00003# Delay import _tkinter until we have set TCL_LIBRARY,
4# so that Tcl_FindExecutable has a chance to locate its
5# encoding directory.
6
7# Unfortunately, we cannot know the TCL_LIBRARY directory
8# if we don't know the tcl version, which we cannot find out
9# without import Tcl. Fortunately, Tcl will itself look in
10# <TCL_LIBRARY>\..\tcl<TCL_VERSION>, so anything close to
11# the real Tcl library will do.
12
13prefix = os.path.join(sys.prefix,"tcl")
14# if this does not exist, no further search is needed
15if os.path.exists(prefix):
Guido van Rossume014a132006-08-19 16:53:45 +000016 if "TCL_LIBRARY" not in os.environ:
Martin v. Löwis4ca196d2002-02-24 16:51:45 +000017 for name in os.listdir(prefix):
18 if name.startswith("tcl"):
19 tcldir = os.path.join(prefix,name)
20 if os.path.isdir(tcldir):
21 os.environ["TCL_LIBRARY"] = tcldir
Martin v. Löwis838a3592002-11-09 19:01:44 +000022 # Compute TK_LIBRARY, knowing that it has the same version
23 # as Tcl
Martin v. Löwis4ca196d2002-02-24 16:51:45 +000024 import _tkinter
25 ver = str(_tkinter.TCL_VERSION)
Guido van Rossume014a132006-08-19 16:53:45 +000026 if "TK_LIBRARY" not in os.environ:
Martin v. Löwis838a3592002-11-09 19:01:44 +000027 v = os.path.join(prefix, 'tk'+ver)
28 if os.path.exists(os.path.join(v, "tclIndex")):
29 os.environ['TK_LIBRARY'] = v
30 # We don't know the Tix version, so we must search the entire
31 # directory
Guido van Rossume014a132006-08-19 16:53:45 +000032 if "TIX_LIBRARY" not in os.environ:
Martin v. Löwis838a3592002-11-09 19:01:44 +000033 for name in os.listdir(prefix):
34 if name.startswith("tix"):
35 tixdir = os.path.join(prefix,name)
36 if os.path.isdir(tixdir):
37 os.environ["TIX_LIBRARY"] = tixdir