Unbuffer stopped working months ago

I find the "unbuffer" command very important and useful, because I am running python code, and I don't think I can just put something equivalent to fflush() everywhere.

I used to use it just fine: unbuffer python foo.py | tee filename.log

A few months ago, I'm not sure if I had allowed my Ubuntu 16.04 to auto update some software, and it stopped working.

$ unbuffer
can't find package Expect
    while executing
"package require Expect"
    (file "/usr/bin/unbuffer" line 6)

I tried editing some files and changing Expect to lower case expect but it didn't work.

I tried (months ago) using apt-get tools to uninstall and reinstall Expect, but to no avail. I'm surprised I can't google this and find others complaining about it not working.

I just tried it on a friend's 18.04 Ubuntu. He has never used it, he downloaded it with apt-get and gets the same failure message. Any help appreciated.

Thanks @pynexj for the suggestion to cat /usr/bin/unbuffer:

#!/bin/sh
# -*- tcl -*-
# The next line is executed by /bin/sh, but not tcl \
exec tclsh8.6 "$0" ${1+"$@"}

package require expect


# -*- tcl -*-
# Description: unbuffer stdout of a program
# Author: Don Libes, NIST

if {[string compare [lindex $argv 0] "-p"] == 0} {
    # pipeline
    set stty_init "-echo"
    eval [list spawn -noecho] [lrange $argv 1 end]
    close_on_eof -i $user_spawn_id 0
    interact {
    eof {
        # flush remaining output from child
        expect -timeout 1 -re .+
        return
    }
    }
} else {
    set stty_init "-opost"
    set timeout -1
    eval [list spawn -noecho] $argv
    expect
    exit [lindex [wait] 3]
}

I have been using conda on this machine, but I'm running these tests in a terminal where I have not done any source activate. The first item in my path is /home/myusername/anaconda3/bin , if that matters.

$ apt list --installed | grep -i expect

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

expect/xenial,now 5.45-7 amd64 [installed]
python3-pexpect/xenial,xenial,now 4.0.1-1 all [installed]
tcl-expect/xenial,now 5.45-7 amd64 [installed,automatic]

$ locate '*expect*pkgIndex.tcl'
/usr/lib/tcltk/x86_64-linux-gnu/expect5.45/pkgIndex.tcl

Thanks @glenn jackman, I found that my tclsh is in ~/anaconda3/bin/tclsh and points to tclsh8.6 I guess this means it was installed as part of my conda installation. As noted above, anaconda3/bin is at the top of my PATH. I haven't built anything myself.

Do we know if 8.6 is old or new? Should I try to do a apt-get update on tcl or tclsh, outside of conda stuff, and see if that helps?


I believe to have bumped into the exact same problem, primarily caused by the installation of Anaconda. Looks like my system was turning to what Anaconda brought with itself, rather than what had been installed ages ago - and otherwise still present.

In accordance with https://anaconda.org/Eumetsat/expect, I only needed to issue a

conda install -c eumetsat expect

to get things back in order.