Skip to content

Instantly share code, notes, and snippets.

@jedie
Last active August 26, 2015 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jedie/2c50f95c2dff9d63d5a4 to your computer and use it in GitHub Desktop.
Save jedie/2c50f95c2dff9d63d5a4 to your computer and use it in GitHub Desktop.
Here some example outputs:
===============================================================================
sys.platform.....: win32
Python info......: CPython v3.4.3 [MSC v.1600 32 bit (Intel)]
sys.prefix.......: C:\Python34
sys.real_prefix..: <not in a virtualenv>
* Apply Tk fix.
TCL_LIBRARY..: C:\Python34\tcl\tcl8.6
TIX_LIBRARY..: C:\Python34\tcl\tix8.4.3
TK_LIBRARY...: C:\Python34\tcl\tk8.6
Tkinter patchlevel: 8.6.1
===============================================================================
sys.platform.....: win32
Python info......: Python 2.7.9 [PyPy 2.6.0 with MSC v.1500 32 bit]
sys.prefix.......: C:\Users\jens\AppData\Roaming\PyPy2_env
sys.real_prefix..: C:\pypy-2.6.0-win32
* Apply Tk fix.
TCL_LIBRARY..: C:\pypy-2.6.0-win32\tcl\tcl8.5
TIX_LIBRARY..: <not set>
TK_LIBRARY...: C:\pypy-2.6.0-win32\tcl\tk8.5
Traceback (most recent call last):
File "<builtin>/app_main.py", line 75, in run_toplevel
File "tkinter_fix_test.py", line 122, in <module>
print("Tkinter patchlevel:", tk.Tcl().eval('info patchlevel'))
File "C:\pypy-2.6.0-win32\lib-python\2.7\lib-tk\Tkinter.py", line 1912, in Tcl
return Tk(screenName, baseName, className, useTk)
File "C:\pypy-2.6.0-win32\lib-python\2.7\lib-tk\Tkinter.py", line 1810, in __i
nit__
self.tk = _tkinter.create(screenName, baseName, className, interactive, want
objects, useTk, sync, use)
File "C:\Users\jens\AppData\Roaming\PyPy2_env\lib_pypy\_tkinter\__init__.py",
line 30, in create
interactive, wantobjects, wantTk, sync, use)
File "C:\Users\jens\AppData\Roaming\PyPy2_env\lib_pypy\_tkinter\app.py", line
142, in __new__
Tcl_AppInit(self)
File "C:\Users\jens\AppData\Roaming\PyPy2_env\lib_pypy\_tkinter\app.py", line
35, in Tcl_AppInit
app.raiseTclError()
File "C:\Users\jens\AppData\Roaming\PyPy2_env\lib_pypy\_tkinter\app.py", line
154, in raiseTclError
raise TclError(tkffi.string(tklib.Tcl_GetStringResult(self.interp)))
TclError: Can't find a usable init.tcl in the following directories:
C:/Users/jens/AppData/Roaming/PyPy2_env/lib/tcl8.5 C:/Users/jens/AppData/Roa
ming/PyPy2_env/lib/tcl8.5 C:/Users/jens/AppData/Roaming/lib/tcl8.5 C:/Users/jens
/AppData/Roaming/PyPy2_env/library C:/Users/jens/AppData/Roaming/library C:/User
s/jens/AppData/Roaming/tcl8.5.13/library C:/Users/jens/AppData/tcl8.5.13/library
This probably means that Tcl wasn't installed properly.
===============================================================================
sys.platform.....: win32
Python info......: Python 2.7.9 [PyPy 2.6.0 with MSC v.1500 32 bit]
sys.prefix.......: C:\pypy-2.6.0-win32
sys.real_prefix..: <not in a virtualenv>
* Apply Tk fix.
TCL_LIBRARY..: C:\pypy-2.6.0-win32\tcl\tcl8.5
TIX_LIBRARY..: <not set>
TK_LIBRARY...: C:\pypy-2.6.0-win32\tcl\tk8.5
Traceback (most recent call last):
File "<builtin>/app_main.py", line 75, in run_toplevel
File "tkinter_fix_test.py", line 122, in <module>
print("Tkinter patchlevel:", tk.Tcl().eval('info patchlevel'))
File "C:\pypy-2.6.0-win32\lib-python\2.7\lib-tk\Tkinter.py", line 1912, in Tcl
return Tk(screenName, baseName, className, useTk)
File "C:\pypy-2.6.0-win32\lib-python\2.7\lib-tk\Tkinter.py", line 1810, in __i
nit__
self.tk = _tkinter.create(screenName, baseName, className, interactive, want
objects, useTk, sync, use)
File "C:\pypy-2.6.0-win32\lib_pypy\_tkinter\__init__.py", line 30, in create
interactive, wantobjects, wantTk, sync, use)
File "C:\pypy-2.6.0-win32\lib_pypy\_tkinter\app.py", line 142, in __new__
Tcl_AppInit(self)
File "C:\pypy-2.6.0-win32\lib_pypy\_tkinter\app.py", line 35, in Tcl_AppInit
app.raiseTclError()
File "C:\pypy-2.6.0-win32\lib_pypy\_tkinter\app.py", line 154, in raiseTclErro
r
raise TclError(tkffi.string(tklib.Tcl_GetStringResult(self.interp)))
TclError: Can't find a usable init.tcl in the following directories:
C:/lib/tcl8.5 C:/lib/tcl8.5 C:/lib/tcl8.5 C:/library C:/library C:/tcl8.5.13
/library C:/tcl8.5.13/library
This probably means that Tcl wasn't installed properly.
===============================================================================
sys.platform.....: win32
Python info......: CPython v2.7.10 [MSC v.1500 32 bit (Intel)]
sys.prefix.......: C:\Users\jens\AppData\Roaming\DragonPy_env_py2
sys.real_prefix..: C:\Python27
* Apply Tk fix.
TCL_LIBRARY..: C:\Python27\tcl\tcl8.5
TIX_LIBRARY..: C:\Python27\tcl\tix8.4.3
TK_LIBRARY...: C:\Python27\tcl\tk8.5
Tkinter patchlevel: 8.5.15
===============================================================================
sys.platform.....: win32
Python info......: CPython v2.7.10 [MSC v.1500 32 bit (Intel)]
sys.prefix.......: C:\Python27
sys.real_prefix..: <not in a virtualenv>
* Apply Tk fix.
TCL_LIBRARY..: C:\Python27\tcl\tcl8.5
TIX_LIBRARY..: C:\Python27\tcl\tix8.4.3
TK_LIBRARY...: C:\Python27\tcl\tk8.5
Tkinter patchlevel: 8.5.15
===============================================================================
sys.platform.....: linux2
Python info......: CPython v2.7.6 [GCC 4.8.2]
sys.prefix.......: /usr
sys.real_prefix..: <not in a virtualenv>
* No Windows -> no fix needed.
TCL_LIBRARY..: <not set>
TIX_LIBRARY..: <not set>
TK_LIBRARY...: <not set>
Tkinter patchlevel: 8.6.1
===============================================================================
sys.platform.....: linux
Python info......: CPython v3.4.0 [GCC 4.8.2]
sys.prefix.......: /usr
sys.real_prefix..: <not in a virtualenv>
* No Windows -> no fix needed.
TCL_LIBRARY..: <not set>
TIX_LIBRARY..: <not set>
TK_LIBRARY...: <not set>
Tkinter patchlevel: 8.6.1
===============================================================================
sys.platform.....: linux
Python info......: CPython v3.4.0 [GCC 4.8.2]
sys.prefix.......: /home/jens/DragonPy_env
sys.real_prefix..: /usr
* No Windows -> no fix needed.
TCL_LIBRARY..: <not set>
TIX_LIBRARY..: <not set>
TK_LIBRARY...: <not set>
Tkinter patchlevel: 8.6.1
from __future__ import absolute_import, division, print_function
import os
import sys
import platform
def fix_virtualenv_tkinter():
"""
work-a-round for tkinter under windows in a virtualenv:
"TclError: Can't find a usable init.tcl..."
Known bug, see: https://github.com/pypa/virtualenv/issues/93
There are "fix tk" file here:
C:\Python27\Lib\lib-tk\FixTk.py
C:\Python34\Lib\tkinter\_fix.py
These modules will be automatic imported by tkinter import.
The fix set theses environment variables:
TCL_LIBRARY C:\Python27\tcl\tcl8.5
TIX_LIBRARY C:\Python27\tcl\tix8.4.3
TK_LIBRARY C:\Python27\tcl\tk8.5
TCL_LIBRARY C:\Python34\tcl\tcl8.6
TIX_LIBRARY C:\Python34\tcl\tix8.4.3
TK_LIBRARY C:\Python34\tcl\tk8.6
but only if:
os.path.exists(os.path.join(sys.prefix,"tcl"))
And the virtualenv activate script will change the sys.prefix
to the current env. So we temporary change it back to sys.real_prefix
and import the fix module.
If the fix module was imported before, then we reload it.
"""
if "TCL_LIBRARY" in os.environ:
# Fix not needed (e.g. virtualenv issues #93 fixed?)
return
if not hasattr(sys, "real_prefix"):
# we are not in a activated virtualenv
return
if sys.version_info[0] == 2:
# Python v2
virtualprefix = sys.prefix
sys.prefix = sys.real_prefix
import FixTk
if "TCL_LIBRARY" not in os.environ:
reload(FixTk)
sys.prefix = virtualprefix
else:
# Python v3
virtualprefix = sys.base_prefix
sys.base_prefix = sys.real_prefix
from tkinter import _fix
if "TCL_LIBRARY" not in os.environ:
from imp import reload
reload(_fix)
sys.base_prefix = virtualprefix
def get_python_info():
implementation = platform.python_implementation()
if implementation == "CPython":
return "%s v%s [%s]" % (
implementation,
platform.python_version(),
platform.python_compiler(),
)
# e.g.: CPython v2.7.6 [GCC 4.8.2]
elif implementation == "PyPy":
ver_info = sys.version.split("(", 1)[0]
ver_info += sys.version.split("\n")[-1]
return "Python %s" % ver_info
# e.g.: Python 2.7.6 [PyPy 2.3.1 with GCC 4.8.2]
else:
return "%s %s" % (
sys.executable,
sys.version.replace("\n", " ")
)
if __name__ == "__main__":
print("sys.platform.....:", sys.platform)
print("Python info......:", get_python_info())
print("sys.prefix.......:", sys.prefix)
print("sys.real_prefix..:", getattr(sys, "real_prefix", "<not in a virtualenv>"))
print()
if sys.platform.startswith("win"):
print(" * Apply Tk fix.")
fix_virtualenv_tkinter()
else:
print(" * No Windows -> no fix needed.")
if sys.version_info[0] == 3:
import tkinter as tk
else:
import Tkinter as tk
print()
print("TCL_LIBRARY..:", os.environ.get("TCL_LIBRARY", "<not set>"))
print("TIX_LIBRARY..:", os.environ.get("TIX_LIBRARY", "<not set>"))
print("TK_LIBRARY...:", os.environ.get("TK_LIBRARY", "<not set>"))
print()
print("Tkinter patchlevel:", tk.Tcl().eval('info patchlevel'))
tk._test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment