Skip to content

Tkinter - fails in a virtual env #56

@vbabiy

Description

@vbabiy

When a virtualenv which shares the global environment site-packges is used for Tk based application using the global Tk.

Tkinter cannot initialise correctly in a virtualenv as it fails to correctly search for it's resources - which are still in the global python environment.

\Documents and Settings\Roger\Desktop\windows-install-bits>cd \venvtest

C:\venvtest>Scripts\activate.bat
(venvtest) C:\venvtest>python
Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
>>> f= Tk()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'Tk' is not defined
>>> f= Tkinter.Tk()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\Python26\Lib\lib-tk\Tkinter.py", line 1643, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, want
objects, useTk, sync, use)
_tkinter.TclError: Can't find a usable init.tcl in the following directories:
    c:/Python26/lib/tcl8.5 c:/venvtest/lib/tcl8.5 c:/lib/tcl8.5 c:/venvtest/libr
ary c:/library c:/tcl8.5.2/library c:/tcl8.5.2/library



This probably means that Tcl wasn't installed properly.

>>> ^Z


(venvtest) C:\venvtest>deactivate

What I would expect is for a virtual env to work the same as the globale environment like so:--

C:\venvtest>c:\Python26\python.exe
Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
>>> f = Tkinter.Tk()
>>> ^Z


C:\venvtest>

After some experimentation I have found that copying c:\python26\tcl{tcl,tk}8.5 directories into the c:\venvtest\Libs solve the issues.


Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions