a Python package for Tcl

This package allows the execution of Python code from a Tcl interpreter, as in:
package require tclpython 4
set interpreter [python::interp new]
$interpreter exec {print("Hello World")}
puts [$interpreter eval 3/2.0]
python::interp delete $interpreter
which outputs:
Hello World

and, starting with version 4.0, execution of Tcl code from Python interpreters, as in:
package require tclpython 4
set interpreter [python::interp new]
puts [$interpreter eval {tcl.eval('clock format [clock seconds]')}]
python::interp delete $interpreter

It works by creating one or more embedded Python interpreters and sending them strings to evaluate or execute. Modules can be loaded in the Python interpreter as if it were the real Python program.

The commands created by the package are very simple:

As expected, eval returns the Python interpreter result or reports an error at the Tcl level when the Python interpreter itself fails in executing the code string, while exec simply lets the Python interpreter execute the code and returns nothing or eventually report an error.

You can create several Python interpreters, if the tclpython package was linked against a Python library compiled with threads support, otherwise only 1 Python interpreter can exist at a time.


Upgrading from tclpython version 2

In tclpython version 2, only the eval command was available to an interpreter. Some such invocations, generally that return nothing, need to be converted to the exec command, as the following examples show:

Send your comments, complaints, ... to
My homepage is at