Virtualenv: TclError Can't find a usable init.tcl
Asked Answered
A

2

9

the issue: running Python's matplotib from a Windows virtual environment as reported & discussed Github ticket 93 and a relevant suggested fix here.

Code (myp.py):

     import matplotlib.pyplot as pl
     import Tkinter as tk
     # insert code to read/load mydata
     pl.plot(mydata['foo'],mydata['bar'],'*')

Tcl Error:

 _tkinter.TclError: Can't find a usable init.tcl in the following directories: 
C:/Python27/lib/tcl8.5 C:/Users/Remi/MyVirtEnv/lib/tcl8.5....(ect)

Fix attempt 1: as suggested in ticket above, I added the following env. variables to path in batch file activate.bat located in C:/Users/Remi/MyVirtEnv/Scripts/:

set "TCL_LIBRARY=C:\Python27\tcl\tcl8.5"
set "TK_LIBRARY=C:\Python27\tcl\tk8.5"

Not resolved this way. Potentially relevant info: using PyCharm IDE with the following configuration:

Environment variables: PYTHONUNBUFFERED=1
Python interpreter: python 2.7.10 virtualenv at C:\Users\Remi\MyVirtEnv
"buttons checked": Add content roots and Add source roots to PYTHONPATH

Any help I could get would be much appreciated.

Ashmore answered 19/2, 2016 at 19:30 Comment(5)
Is there an init.tcl in any of the directories it lists?Grimonia
@ Donal: yep in /Python27/tcl/tcl8.5. Btw, the ugliest fix for now was to copy /tk8.5 and /tcl8.5 to `C:\Users\Remi\MyVirtEnv\Lib`Ashmore
@Ashmore Did you find any elegant solution on this? I have same issue.Arnoldarnoldo
@ tomab: not really. The above fixed it for me and I did not look back.Ashmore
The problem is that something is causing libtcl.dll to not be able to locate the associated init.tcl. There's various reasons why that might happen, but most come down to people moving part of the installation around without moving the rest of it, or using the wrong value in the TCL_LIBRARY environment variable. I've a long-term fix for this — involving building a combined installation file — but that's still in alpha.Grimonia
C
2

After adding the following environment variables to path in batch file activate.bat located in the virtual environment, e.g.: C:/Users/Remi/MyVirtEnv/Scripts/:

set "TCL_LIBRARY=C:\Python27\tcl\tcl8.5"
set "TK_LIBRARY=C:\Python27\tcl\tk8.5"

it is able to launch IDLE in virtual environment.

Make sure the path is valid, e.g. "C:\Python27\tcl\tcl8.5"

Cilka answered 24/3, 2022 at 9:59 Comment(0)
A
0

Went through this as well, tried all the suggested steps (other than reinstalling, etc).

What "solved" it was copying everything inside C:\Python27\tcl to the virtual environment's \Lib.

At first I'd just copied \tcl.8.5 and \tk8.5 but it was buggy with matplotlib, so copying everything actually made it work. Definitely an ugly fix as mentioned in a previous comment.

Astigmia answered 8/8, 2024 at 9:57 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.