Version 30 of TCLLIBPATH

Updated 2012-06-29 09:40:16 by LGT

Purpose: to document the use of another of the magic names in Tcl. More formally, TCLLIBPATH is an environment variable; inside Tcl you can retrieve it with $::env(TCLLIBPATH).

What is its purpose?

To provide user specified locations to add to the package search path.

What is the relationship between TCLLIBPATH and Tcl's ::auto_path variable?

What is its format?

A tcl list of directory paths (unix-style paths for Win32 users). e.g:

set TCLLIBPATH [list /opt/tcl/site-lib /users/pat/working]

What are some good reasons to set it?

  • site specific packages

PT 20-Jul-2004: I like to keep all my local packages separate from the ActiveTcl installation that I use as a base. So I install all additional packages to a site-lib directory and then set TCLLIBPATH to this directory path. With this in place a [package require XYZ] command will search ActiveTcl and my site-lib directory for the most recent version of XYZ.

  • test a package without installing.

Questions relating to TCLLIBPATH

Why don't I see TCLLIBPATH set in my program?

D. McC 08-Nov-2004: Well ... what about this?

 [[email protected] david]% puts $::env(HOME)


 [[email protected] david]% puts $::env(TCLLIBPATH)

can't read "::env(TCLLIBPATH)": no such variable

This happens on my Mandrake linux 10.0 system, running Tcl 8.4 from the tcl-8.4.5-3mdk RPM package. Why no TCLLIBPATH, I wonder?

RS: Because nobody has set it? :-) Normally it's best to use as few env variables as possible - it should only be used to override some default behavior, which for finding libs is:

 [file dir [info nameofexe]]/../lib

and similar variations.

LV David, environmental variables are ones that someone external to Tcl set. In many cases, they are set by a user. In a few cases, a shell command or some other utility (such as Modules for instance), may set the environment variables. So many times, one won't find them set. This is different than magic names like the $argc variable, etc.

What specific path goes into the TCLLIBPATH?

LV 2009-Jun-29

I download a package onto my machine. The package has a README, a demo directory, a lib directory, etc. Within the lib directory I see 3 sub-directories, and within the sub-directories are the pkgIndex.tcl file, etc.

So the basic layout is:

Installation directory/

So, what path(s) go into TCLLIBPATH? the path to the lib/ , or each of the individual packages?


PT: the lib directory.

LV PT, thank you for the answer. I tried using that, and ran into my long time nemesis - Windows folders with spaces in the names. So eventually, when I have time, I need to change to using file join to set the TCLLIBPATH rather than just hard coding the path, so that it has some chance of working.

See also TCL_LIBRARY, auto_path.

msubbareddy - 2010-08-03 14:27:14


List the installed libraries on linux tcl platform as teacup does on Windows ActiveTcl

ls -l [list [file dirname [info library]]]

LGT Example on Windows with Git version 1.7.10-preview20120409

I ran git, then do 'cd' to be in HOME directory and then add file .bashrc with these lines :

 $ cd
 $ cat .bashrc
 TCLLIBPATH=" . C:/Tcl/lib"

Then at the next start of git, you will be able to use library packages from external (to git) Tcl installation.

Space character seems to be required at the beginning of TCLLIBPATH value : you can try the following lines on command line to experience it

 $ TCLLIBPATH=". C:/Tcl/lib"
 $ export TCLLIBPATH
 $ tclsh
 % package require Expect
 can't find package Expect
 % exit
 $ TCLLIBPATH=" . C:/Tcl/lib "
 $ export TCLLIBPATH
 $ tclsh
 % package require Expect
 % exit