0

everyone, I am using tabula-py in python to extract table from pdfs. I used following codes.

import tabula

table_temp = tabula.read_pdf('./example_pdf/sample1.pdf',pages=11)

However, I got the error message as pasted below, in which I was told "no such file or directory: 'java'". I have installed Java in the following folder

"/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home". 

Could anyone help me on solving the problem?

Thanks.


FileNotFoundError                         Traceback (most recent call last)
<ipython-input-4-41c9ba6fd519> in <module>()
----> 1 table_temp = tabula.read_pdf('./example_pdf/sample1.pdf',pages=11)

/Users/Myworld/anaconda/lib/python3.5/site-packages/tabula/wrapper.py in read_pdf(input_path, **kwargs)
     64 
     65     try:
---> 66         output = subprocess.check_output(args)
     67     finally:
     68         if is_url:

/Users/Myworld/anaconda/lib/python3.5/subprocess.py in check_output(timeout, *popenargs, **kwargs)
    314 
    315     return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
--> 316                **kwargs).stdout
    317 
    318 

/Users/Myworld/anaconda/lib/python3.5/subprocess.py in run(input, timeout, check, *popenargs, **kwargs)
    381         kwargs['stdin'] = PIPE
    382 
--> 383     with Popen(*popenargs, **kwargs) as process:
    384         try:
    385             stdout, stderr = process.communicate(input, timeout=timeout)

/Users/Myworld/anaconda/lib/python3.5/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds)
    674                                 c2pread, c2pwrite,
    675                                 errread, errwrite,
--> 676                                 restore_signals, start_new_session)
    677         except:
    678             # Cleanup if the child failed starting.

/Users/Myworld/anaconda/lib/python3.5/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
   1280                             else:
   1281                                 err_msg += ': ' + repr(orig_executable)
-> 1282                     raise child_exception_type(errno_num, err_msg)
   1283                 raise child_exception_type(err_msg)
   1284 

FileNotFoundError: [Errno 2] No such file or directory: 'java'
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Tao Wang
  • 1
  • 1
  • 1
  • 1
  • is the `java` executable registered in the path? if yes, you should be able to `java --version` from your os command line utility (eg. cmd, bash). what is your os anyway? – Bagus Tesa Jun 12 '17 at 01:25
  • 1
    Thanks a lot for your comments. When I typed java --version in terminal in Mac, I got "-bash: java: command not found". – Tao Wang Jun 12 '17 at 02:24
  • then you would need to put the `java/bin` directory into path that being loaded by your tools.. in ubuntu or centos, that'd be `.bashrc`. try to look on it. – Bagus Tesa Jun 12 '17 at 04:23
  • Possible duplicate of [Setting JAVA\_HOME environment variable on MAC OSX 10.9](https://stackoverflow.com/questions/22842743/setting-java-home-environment-variable-on-mac-osx-10-9) – OneCricketeer Jun 12 '17 at 04:39
  • Not clear how you installed Java, but you must update the PATH – OneCricketeer Jun 12 '17 at 04:40
  • Thanks a lot, friends. I understand that you all suggested to reset the path for JAVA. This is to reset JAVA_HOME if I understand correctly. In order to do that, I first check where my JAVA is installed by typing "echo $JAVA_HOME", I got "/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home". Then I typed "open -e .bash_profile" and added "export JAVA_HOME=$(/usr/libexec/java_home)" to the file and reload it. After doing this, I thought I have correctly set path for Java. But I still got "-bash: java: command not found" when I typed java --version in terminal. Any ideas? Thanks! – Tao Wang Jun 12 '17 at 18:18
  • Hi, dear friends, I want to add that I finally solved the problem. I not only added "export JAVA_HOME=$(/usr/libexec/java_home)" , but also "export PATH=$JAVA_HOME/bin:$PATH" to the .bash_profile. And now the mac knows where Java is. Thanks a lot for your help. – Tao Wang Jun 12 '17 at 18:43

1 Answers1

2

I had run into the same error. The line actually causing the error for me was subprocess.call('java').

Installing Java on my machine fixed the error for me.

If installing Java still doesn't solve the problem for you, try running which java, and add the output directory to your PATH environment variable.

Dharman
  • 30,962
  • 25
  • 85
  • 135
akki
  • 2,021
  • 1
  • 24
  • 35