Question

I successfully ran this script in Python, but IPython notebook threw an exception. What could be the problem?

import os
from subprocess import call, Popen, PIPE, STDOUT

command = "java -cp \"C:\mallet-2.0.7\class;C:\mallet-2.0.7\lib\mallet-deps.jar\" cc.mallet.fst.SimpleTagger --train true --model-file nouncrf train.txt"
p = Popen(command, stdout=PIPE, stderr=STDOUT, shell = True)

for line in p.stdout:
     print line


Exception in thread "main" java.io.FileNotFoundException: train.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
at cc.mallet.fst.SimpleTagger.main(SimpleTagger.java:504)
Was it helpful?

Solution

Apparently the question is not related to Python at all, as it is a Java exception, not a Python one. Most probably, the file (train.txt) is looked for in a current directory. When you run your script in Python, the current directory may differ from what it is in IPython. Is the Java program able to accept absolute file path? If yes, you may specify the absolute path in command line for Java program.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top