Martin v. Löwis | 4ca196d | 2002-02-24 16:51:45 +0000 | [diff] [blame] | 1 | import sys, os |
Guido van Rossum | ea32cbb | 2001-10-12 15:34:29 +0000 | [diff] [blame] | 2 | |
Martin v. Löwis | 4ca196d | 2002-02-24 16:51:45 +0000 | [diff] [blame] | 3 | # 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 | |
| 13 | prefix = os.path.join(sys.prefix,"tcl") |
Christian Heimes | 99170a5 | 2007-12-19 02:07:34 +0000 | [diff] [blame] | 14 | if not os.path.exists(prefix): |
| 15 | # devdir/../tcltk/lib |
| 16 | prefix = os.path.join(sys.prefix, os.path.pardir, "tcltk", "lib") |
| 17 | prefix = os.path.abspath(prefix) |
Martin v. Löwis | 4ca196d | 2002-02-24 16:51:45 +0000 | [diff] [blame] | 18 | # if this does not exist, no further search is needed |
| 19 | if os.path.exists(prefix): |
Guido van Rossum | e014a13 | 2006-08-19 16:53:45 +0000 | [diff] [blame] | 20 | if "TCL_LIBRARY" not in os.environ: |
Martin v. Löwis | 4ca196d | 2002-02-24 16:51:45 +0000 | [diff] [blame] | 21 | for name in os.listdir(prefix): |
| 22 | if name.startswith("tcl"): |
| 23 | tcldir = os.path.join(prefix,name) |
| 24 | if os.path.isdir(tcldir): |
| 25 | os.environ["TCL_LIBRARY"] = tcldir |
Martin v. Löwis | 838a359 | 2002-11-09 19:01:44 +0000 | [diff] [blame] | 26 | # Compute TK_LIBRARY, knowing that it has the same version |
| 27 | # as Tcl |
Martin v. Löwis | 4ca196d | 2002-02-24 16:51:45 +0000 | [diff] [blame] | 28 | import _tkinter |
| 29 | ver = str(_tkinter.TCL_VERSION) |
Guido van Rossum | e014a13 | 2006-08-19 16:53:45 +0000 | [diff] [blame] | 30 | if "TK_LIBRARY" not in os.environ: |
Martin v. Löwis | 838a359 | 2002-11-09 19:01:44 +0000 | [diff] [blame] | 31 | v = os.path.join(prefix, 'tk'+ver) |
| 32 | if os.path.exists(os.path.join(v, "tclIndex")): |
| 33 | os.environ['TK_LIBRARY'] = v |
| 34 | # We don't know the Tix version, so we must search the entire |
| 35 | # directory |
Guido van Rossum | e014a13 | 2006-08-19 16:53:45 +0000 | [diff] [blame] | 36 | if "TIX_LIBRARY" not in os.environ: |
Martin v. Löwis | 838a359 | 2002-11-09 19:01:44 +0000 | [diff] [blame] | 37 | for name in os.listdir(prefix): |
| 38 | if name.startswith("tix"): |
| 39 | tixdir = os.path.join(prefix,name) |
| 40 | if os.path.isdir(tixdir): |
| 41 | os.environ["TIX_LIBRARY"] = tixdir |