getting error "/usr/bin/env: th: No such file or directory" #166

tonyzzzzz opened this Issue Jul 23, 2016 · 4 comments


None yet

4 participants

tonyzzzzz commented Jul 23, 2016 edited

I tried to convert the to a web service (code is shown below). Everythig is fine if I log into the container and run the py script
root@cc0d5ec:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@cc0d5ec:/# python /root/openface/demos/

However, error occurs when I do this using docker exec:
c:\DockerTemp>docker exec -it facecompare python /root/openface/demos/
/usr/bin/env: th: No such file or directory

Traceback (innermost first)

/usr/local/lib/python2.7/dist-packages/openface/ in forwardPath
""".format(self.cmd, ...
▶ Local vars
/usr/local/lib/python2.7/dist-packages/openface/ in forward
rep = self.forwardPath(t) ...
▶ Local vars
/root/openface/demos/ in getRep
rep = net.forward(alignedFace)
▶ Local vars
/root/openface/demos/ in GET
d = getRep(os.path.join(fileDir, '..','..','..','mnt','1.jpg')) - getRep(os.path.join(fileDir, '..','..','..','mnt','a1.jpg'))
▶ Local vars
/usr/local/lib/python2.7/dist-packages/web/ in handle_class
return tocall(*args) ...
▶ Local vars
/usr/local/lib/python2.7/dist-packages/web/ in _delegate
return handle_class(cls) ...
▶ Local vars
/usr/local/lib/python2.7/dist-packages/web/ in handle
return self._delegate(fn, self.fvars, args) ...
▶ Local vars
/usr/local/lib/python2.7/dist-packages/web/ in process
return self.handle() ...
▶ Local vars

Can anyone please help here?

My pythoncode -

`#!/usr/bin/env python

import web
import xml.etree.ElementTree as ET
import cv2
import itertools
import os
import numpy as np
import openface
import argparse

tree = ET.parse('user_data.xml')

root = tree.getroot()

urls = (
'/compare', 'compare_two_pic',
'/listpic/(.*)', 'list_pic'

set up the path

fileDir = os.path.dirname(os.path.realpath(file))
modelDir = os.path.join(fileDir, '..', 'models')
dlibModelDir = os.path.join(modelDir, 'dlib')
openfaceModelDir = os.path.join(modelDir, 'openface')

parser = argparse.ArgumentParser()
parser.add_argument('--dlibFacePredictor', type=str, help="Path to dlib's face predictor.",
default=os.path.join(dlibModelDir, "shape_predictor_68_face_landmarks.dat"))
parser.add_argument('--networkModel', type=str, help="Path to Torch network model.",
default=os.path.join(openfaceModelDir, 'nn4.small2.v1.t7'))
parser.add_argument('--imgDim', type=int,
help="Default image dimension.", default=96)
parser.add_argument('--verbose', action='store_true')
args = parser.parse_args()

align = openface.AlignDlib(args.dlibFacePredictor)
net = openface.TorchNeuralNet(args.networkModel, args.imgDim)

def getRep(imgPath):

bgrImg = cv2.imread(imgPath)
if bgrImg is None:
    raise Exception("Unable to load image: {}".format(imgPath))
rgbImg = cv2.cvtColor(bgrImg, cv2.COLOR_BGR2RGB)

bb = align.getLargestFaceBoundingBox(rgbImg)
if bb is None:
    raise Exception("Unable to find a face: {}".format(imgPath))

alignedFace = align.align(args.imgDim, rgbImg, bb,
if alignedFace is None:
    raise Exception("Unable to align image: {}".format(imgPath))

rep = net.forward(alignedFace)

return rep

app = web.application(urls, globals())

class list_pic:
def GET(self):
output = 'users:[';

    output += ']';
    return output

class compare_two_pic:
def GET(self):
d = getRep(os.path.join(fileDir, '..','..','..','mnt','1.jpg')) - getRep(os.path.join(fileDir, '..','..','..','mnt','a1.jpg'))
d1 =, d)
return str(d1)

if name == "main":`


I think your exec command has to look something like:
'bash -l -c "python /root/openface/demos/"'.

@bamos If you wanted to make a change to the Dockerfile to avoid having to execute scripts like this you can add 'ln -s /root/torch/install/bin/th /usr/local/bin/th' as a final step in the torch install section. It makes running these scripts a little more simple and might avoid more questions related to this in the future.


@luinstra, it worked fine.. thanks!
c:\DockerTemp>docker exec -t facecompare bash -l -c "python /root/openface/demos/" - - [23/Jul/2016 19:27:03] "HTTP/1.1 GET /compare" - 200 OK

@bamos bamos added a commit that referenced this issue Jul 23, 2016
@bamos bamos Dockerfile: Link Torch binaries to /usr/local/bin for #166.
Thanks @luinstra for the suggestion
bamos commented Jul 23, 2016

Thanks for the quick reply here and for the suggestion @luinstra - I've added that to the Dockerfile.


@bamos bamos closed this Jul 23, 2016
@bamos bamos added a commit that referenced this issue Jul 23, 2016
@bamos bamos Dockerfile: Fix link for #166. 131f7bb

I use the mac osx, But I didn't find error as follow:
/usr/bin/env: th: No such file or directory
Where is the th? how to install th in mac osx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment