tylin / coco-caption

Other
1.13k stars 545 forks source link

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

Open rubencart opened 5 years ago

rubencart commented 5 years ago

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']
JunlongFeng commented 5 years ago

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

ynuwm commented 5 years ago

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

rubencart commented 5 years ago

@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))

ynuwm commented 5 years ago

ok, I get it, thank you very much.