3.13.0 tkinter versus venv in windows 10

Just installed python 3.13.0 (release) for testing a tkinter app under windows in a venv. Failed to start. After testing I see these results

In the venv

(py313) C:\Users\rptla\tmp\py313>python
Python 3.13.0 (tags/v3.13.0:60403a5, Oct  7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> root = tkinter.Tk()
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    root = tkinter.Tk()
  File "C:\python313\Lib\tkinter\__init__.py", line 2459, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
              ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_tkinter.TclError: Can't find a usable init.tcl in the following directories:
    C:/python313/lib/tcl8.6 C:/lib/tcl8.6 C:/lib/tcl8.6 C:/library C:/library C:/tcl8.6.14/library C:/tcl8.6.14/library



This probably means that Tcl wasn't installed properly.

>>>

in the base Python I get a better outcome

C:\Python313\Lib\tkinter>\python313\python
Python 3.13.0 (tags/v3.13.0:60403a5, Oct  7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> root=tkinter.Tk()
>>>

what do I need to do to make tkinter work in the windows venv?

2 Likes

I see the exact same problem in Windows 11. Broken in a venv, works fine outside of a VM. This also means that things like matplotlib don’t work without installing another GUI library. (At least, I assume so. I haven’t installed Qt yet to try it out.)

Additionally, my python 3.13 install is under my user account, not for all users. Just in case someone was wondering, as this is different than the OP.

Someone has opened a GitHub issue for this: Tkinter does not run in 3.13.0 Β· Issue #125179 Β· python/cpython Β· GitHub

2 Likes

I can also confirm this happens to me on Windows in Python 3.13: works normally, but doesn’t work in a venv. Same error message.

I added the venv version win 10 Python-3.13.0 tkinter fails in venv Β· Issue #125235 Β· python/cpython Β· GitHub

I tried copying the tcl directory from the installation into the venv top level. In my case that was

cp -pr C:\python313\tcl c:\users\rptla\tmp\py313\tcl

After doing that the tkinter.Tk() test did not raise an exception and running my app starts OK. However, the app leaves a command window running which it’s not supposed to (the app is declared as a gui_script).

FWIW it’s easier to just set TCL_LIBRARY to point at the tcl\tcl8.6 directory in the installation. Again when I do that Tk() works, but starting my app with say pythonw -m…app leaves a command window lying about.

I am seeing this on Windows 11 too. I installed Python 3.13.0 in the default user profile at %LocalAppData%.

It’s easy to fix until a new version is released:

  1. Copy the entire tcl8.6 folder from
    %LocalAppData%\Programs\Python\Python313\tcl
    and paste it into
    %LocalAppData%\Programs\Python\Python313\Lib

  2. Copy the entire tk8.6 folder from
    %LocalAppData%\Programs\Python\Python313\tcl
    and paste it into
    %LocalAppData%\Programs\Python\Python313\Lib\tcl8.6
    i.e. inside the folder you pasted in step 1.

You should end up with a folder structure like this:

    .
    └── %LocalAppData%
        └── Programs
            └── Python
                └── Python313
                    └── Lib
                        └── tcl8.6  # <------- copied from Python313\tcl 
                            β”œβ”€β”€ encoding
                            β”œβ”€β”€ http1.0
                            β”œβ”€β”€ msgs
                            β”œβ”€β”€ opt0.4
                            β”œβ”€β”€ tk8.6  # <------- copied from Python313\tcl
                            β”‚   β”œβ”€β”€ demos
                            β”‚   β”œβ”€β”€ images
                            β”‚   β”œβ”€β”€ msgs
                            β”‚   └── ttk
                            └── tzdata
2 Likes

Thanks, worked for me on Windows 11 and Python 3.13.

1 Like

Yes, this was the fix (Win 10, Python 3.13). Thank you.

The #125235 fix for tkinter in venv should appear in 3.13.1.

2 Likes