【问题标题】:Python tabula-py won't read pdfPython tabula-py 不会读取 pdf
【发布时间】:2017-06-02 08:40:41
【问题描述】:

我正在尝试从一系列 PDF 文件中提取表格,但无法使 tabula-py 工作。我一直在尝试通过 Windows 操作系统上的 Jupyter Notebook 使用它。不幸的是,我得到了同样的结果

‘FileNotFoundError’

每次我尝试使用 read_PDF()。

从我目前在网上找到的情况来看,这个错误似乎是在尝试运行 Tabula java 文件时产生的。我已经正确安装了 java。

对此的任何帮助将不胜感激。

这是我要运行的代码:

    from tabula import read_pdf
    df = read_pdf("https://github.com/tabulapdf/tabula-java/raw/master/src/test/resources/technology/tabula/arabic.pdf")

错误信息:

    FileNotFoundError                         Traceback (most recent call last)
    <ipython-input-78-956ad4697ff7> in <module>()
          1 from tabula import read_pdf
    ----> 2 df = read_pdf("https://github.com/tabulapdf/tabula-java/raw/master/src/test/resources/technology/tabula/arabic.pdf")

    C:\Program Files\Anaconda3\lib\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:

    C:\Program Files\Anaconda3\lib\subprocess.py in check_output(timeout, *popenargs, **kwargs)
        624 
        625     return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
    --> 626                **kwargs).stdout
        627 
        628 

    C:\Program Files\Anaconda3\lib\subprocess.py in run(input, timeout, check, *popenargs, **kwargs)
        691         kwargs['stdin'] = PIPE
        692 
    --> 693     with Popen(*popenargs, **kwargs) as process:
        694         try:
        695             stdout, stderr = process.communicate(input, timeout=timeout)

    C:\Program Files\Anaconda3\lib\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)
        945                                 c2pread, c2pwrite,
        946                                 errread, errwrite,
    --> 947                                 restore_signals, start_new_session)
        948         except:
        949             # Cleanup if the child failed starting.

    C:\Program Files\Anaconda3\lib\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, unused_restore_signals, unused_start_new_session)
       1222                                          env,
       1223                                          cwd,
    -> 1224                                          startupinfo)
       1225             finally:
       1226                 # Child is launched. Close the parent's copy of those pipe

【问题讨论】:

  • 如果您想得到一些答案,您需要提供更多详细信息。请提供工作代码示例以重现您的问题
  • 谢谢@PawelMiech。我刚刚添加了我要运行的代码。干杯

标签: python pdf subprocess tabula


【解决方案1】:

我这样做,然后运行代码

  1. pip install tabula-py

  2. conda install tabula-py

  3. conda install java
  4. from tabula import read_pdf
  5. import pandas as pd
  6. dt = read_pdf('file.pdf', encoding = 'latin1', pages ='all', nospreadsheet = True)

祝你好运……

【讨论】:

    【解决方案2】:

    我在没有为 java.exe 设置 PATH 环境的情况下重现了这个问题。确保为 Java 设置 PATH。也可以看看: https://www.java.com/en/download/help/path.xml

    【讨论】:

    • 非常感谢,@chezou。现在从终端窗口运行良好,但在 Jupyter Notebook 上运行时仍然出现相同的错误。干杯
    【解决方案3】:

    要确保 Windows 可以找到 Java 编译器和解释器: 选择开始 -> 计算机 -> 系统属性 -> 高级系统设置 -> 环境变量 -> 系统变量 -> PATH。 [ 在 Vista 中,选择开始 -> 我的电脑 -> 属性 -> 高级 -> 环境变量 -> 系统变量 -> PATH。 ]

    [ 在 Windows XP 中,选择开始 -> 控制面板 -> 系统 -> 高级 -> 环境变量 -> 系统变量 -> PATH。 ]

    添加 C:\Program Files\Java\jdk1.6.0_27\bin;到 PATH 变量的开头。 单击确定三次。

    【讨论】:

      【解决方案4】:

      我在 Ubuntu 中遇到了同样的问题。

      首先,通过运行 java --version 和 javac --version 检查您机器上安装的 JDK 和 JRE 的版本。每个都应该有一个大于 7 的版本。

      然后使用pip3安装tabula。

      【讨论】:

        【解决方案5】:

        因为您无法找到 PDF 文件。所以首先通过提供绝对或相对路径来查找 PDF 文件。

        import os
        print(os.getcwd())
        print(os.listdir('Other'))
        
        #Locating PDF file with searching and then joining absolute and relative path
        file = os.path.join(os.getcwd(), 'test.pdf')
        

        【讨论】:

          【解决方案6】:
          df = tabula.read_pdf("Danamon - FS - FY-18.pdf", pages = i, guess = False)
          

          使用附加参数 guess = False 对我有用

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2019-01-10
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多