I have tried load thread package inside wish(*.tk) file. Can you please let me, how to use package inside wish(tk) file?
% pkg.tk
#!/usr/bin/wish -f
#!/usr/bin/tclsh8.5
package require Thread
Error:
Error in startup script: can't find package Thread
while executing
"package require Thread"
(file "./pkg.tk" line 4)
It seems that the Thread package is not on the path of locations that Tcl searches when looking for packages.
The standard way of fixing this is via the
TCLLIBPATH
environment variable.You need to find the directory containing the implementation and put the parent directory of that directory in the environment variable before starting the Tcl interpreter. On my system, where the actual implementation is in
/opt/local/lib/thread2.8.5/libthread2.8.5.dylib
, that would be done via:but the locations and filenames most certainly can vary between systems! (The correct location ought to be there by default, but there are ways for other software to cause problems with this. It's really irritating!) Note that you should use
/
instead of\
as the latter is a Tcl metacharacter. If there are multiple locations, theTCLLIBPATH
actually contains a space-separated list.Note that this is different to handling your own application-specific packages. In that case, you should
lappend auto_path $location
the place (or places) to get them from at the start of your main script.