使用tabula-py时“找不到Java”

时间:2017-06-12 01:21:08

标签: java python tabula

大家,我在python中使用tabula-py从pdfs中提取表。我使用以下代码。

import tabula

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

但是,我收到了下面粘贴的错误消息,其中我被告知“没有这样的文件或目录:'java'”。我在以下文件夹中安装了Java

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

有人可以帮我解决问题吗?

感谢。

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'

1 个答案:

答案 0 :(得分:1)

我遇到了同样的错误。实际上导致错误的行是subprocess.call('java')

我机器上的

Installing java为我修复了错误。

如果安装java仍然无法解决问题,请尝试运行which java并将输出目录添加到PATH环境变量中。

HTH