coco-caption icon indicating copy to clipboard operation
coco-caption copied to clipboard

Tokenizer: `OSError: [Errno 2] No such file or directory`

Open rubencart opened this issue 5 years ago • 4 comments

Like in https://github.com/tylin/coco-caption/issues/22#issue-231528122 , I got

OSError: [Errno 2] No such file or directory: 'java'

When running the evaluation, even with java definitely installed. This SO discusses it: https://stackoverflow.com/a/55675914/2332296. I was able to solve it by setting shell=True and making cmd in

p_tokenizer = subprocess.Popen(cmd, cwd=path_to_jar_dirname, stdout=subprocess.PIPE, shell=True)

from

cmd = ['java', '-cp', 'stanford-corenlp-3.4.1.jar', 'edu.stanford.nlp.process.PTBTokenizer', '-preserveLines', '-lowerCase', 'tmpWS5p0Z']

(where 'tmpWS5p0Z' is the name of the tempfile.NamedTemporaryFile that is added), into:

cmd = ['/abs/path/to/java -cp /abs/path/to/stanford-corenlp-3.4.1.jar edu.stanford.nlp.process.PTBTokenizer -preserveLines -lowerCase /abs/path/to/temporary_file']

rubencart avatar Apr 14 '19 13:04 rubencart

I solved this error, by using absolute path in sys.path.append() to include the coco-caption file . I still get this error running in Pycharm,but it works well by using terminal command

JunlongFeng avatar May 10 '19 12:05 JunlongFeng

@rubencart hi, how can I get the name of 'tmpWS5p0Z' according to your answer.

ynuwm avatar Jun 27 '19 08:06 ynuwm

@ynuwm that is automatically added by the line cmd.append(os.path.join(path_to_jar_dirname, os.path.basename(tmp_file.name))). Just change that line into cmd[0] += os.path.join(path_to_jar_dirname, os.path.basename(tmp_file.name))

rubencart avatar Jun 27 '19 09:06 rubencart

ok, I get it, thank you very much.

ynuwm avatar Jun 27 '19 09:06 ynuwm