0

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

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'
4

1 回答 1

2

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

在我的机器上安装 java为我解决了这个错误。

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

高温高压

于 2018-02-27T06:16:44.857 回答