1
+ import os
2
+ import sys
1
3
2
- __version__ = "0.5.0"
4
+
5
+ __version__ = "0.5.1.dev0"
6
+
7
+
8
+ def fix_virtualenv_tkinter ():
9
+ """
10
+ work-a-round for tkinter under windows in a virtualenv:
11
+ "TclError: Can't find a usable init.tcl..."
12
+ Known bug, see: https://github.com/pypa/virtualenv/issues/93
13
+
14
+ There are "fix tk" file here:
15
+
16
+ C:\Python27\Lib\lib-tk\FixTk.py
17
+ C:\Python34\Lib\t kinter\_fix.py
18
+
19
+ These modules will be automatic imported by tkinter import.
20
+
21
+ The fix set theses environment variables:
22
+
23
+ TCL_LIBRARY C:\Python27\t cl\t cl8.5
24
+ TIX_LIBRARY C:\Python27\t cl\t ix8.4.3
25
+ TK_LIBRARY C:\Python27\t cl\t k8.5
26
+
27
+ TCL_LIBRARY C:\Python34\t cl\t cl8.6
28
+ TIX_LIBRARY C:\Python34\t cl\t ix8.4.3
29
+ TK_LIBRARY C:\Python34\t cl\t k8.6
30
+
31
+ but only if:
32
+
33
+ os.path.exists(os.path.join(sys.prefix,"tcl"))
34
+
35
+ And the virtualenv activate script will change the sys.prefix
36
+ to the current env. So we temporary change it back to sys.real_prefix
37
+ and import the fix module.
38
+ If the fix module was imported before, then we reload it.
39
+ """
40
+ if "TCL_LIBRARY" in os .environ :
41
+ # Fix not needed (e.g. virtualenv issues #93 fixed?)
42
+ return
43
+
44
+ if not hasattr (sys , "real_prefix" ):
45
+ # we are not in a activated virtualenv
46
+ return
47
+
48
+ if sys .version_info [0 ] == 2 :
49
+ # Python v2
50
+ virtualprefix = sys .prefix
51
+ sys .prefix = sys .real_prefix
52
+
53
+ import FixTk
54
+
55
+ if "TCL_LIBRARY" not in os .environ :
56
+ reload (FixTk )
57
+
58
+ sys .prefix = virtualprefix
59
+ else :
60
+ # Python v3
61
+ virtualprefix = sys .base_prefix
62
+ sys .base_prefix = sys .real_prefix
63
+
64
+ from tkinter import _fix
65
+
66
+ if "TCL_LIBRARY" not in os .environ :
67
+ from imp import reload
68
+ reload (_fix )
69
+
70
+ sys .base_prefix = virtualprefix
71
+
72
+
73
+ if sys .platform .startswith ("win" ):
74
+ fix_virtualenv_tkinter ()
0 commit comments