If you know the directory where the comm
package is installed (either the directory containing the pkgIndex.tcl
or the immediate parent directory), you should make sure that's on Tcl's auto_path
before trying to package require
the package. The function you need to do that is this:
def add_library_directory(tcl_context, directory_name):
tcl_context.eval("lappend auto_path {}".format(
# This does the trick to make the string substitution fully safe
tkinter._stringify(directory_name)))
interp = tkinter.Tcl()
# Up to you to actually find the location...
add_library_directory(interp, "/path/to/dir")
interp.eval('package require comm')
For details of tkinter._stringify
, which is massively underdocumented despite being very useful, see this other Stack Overflow question: