【问题标题】:AttributeError: module 'camelot' has no attribute 'read_pdf'AttributeError:模块“camelot”没有属性“read_pdf”
【发布时间】:2020-02-11 01:36:21
【问题描述】:

我正在尝试使用 camelot 从 pdf 中提取表格,但出现此属性错误。能否请你帮忙?

import camelot
import pandas as pd
pdf = camelot.read_pdf("Gordian.pdf")

AttributeError Traceback(最近一次调用最后一次) 在 ----> 1 pdf = camelot.read_pdf("Gordian.pdf")

AttributeError: 模块 'camelot' 没有属性 'read_pdf'

【问题讨论】:

标签: python python-camelot


【解决方案1】:

以下是完整安装步骤的链接: https://camelot-py.readthedocs.io/en/master/user/install.html#using-pip

安装后

pip install camelot-py[cv]

这样写:

import camelot.io as camelot

【讨论】:

    【解决方案2】:

    我放弃了尝试让 camelot 在 Jupiter Notebooks 中工作以读取表格,而是安装了以下内容:

    !{sys.executable} -m pip install tabula-py tabulate
    
    from tabula import read_pdf
    from tabulate import tabulate
    
    
    pdf_path = (
        Path.home()
        / "my_pdf.pdf"
    )
    df = read_pdf(str(pdf_path), pages=1)
    df[0]
    

    【讨论】:

      【解决方案3】:

      请检查您的机器上是否安装了 java,转到您的终端并运行“java -version”,如果没有,您将无法使用 Camelot 或 tabula 阅读 pdf,

      安装 java 后,使用命令安装 tabula-py pip install tabula-py.

      from tabula.io import read_pdf
      tables = read_pdf('file.pdf')  # substitute your file name
      

      【讨论】:

        【解决方案4】:

        试试这个:import camelot.io as camelot 这对我有用。

        【讨论】:

          【解决方案5】:

          下载库时请注意下载位置。因为你下载的库可能已经保存在另一个 Python 版本中

          【讨论】:

          • 您好,欢迎来到 SO!请阅读tourHow do I write a good answer? 例如,您可以详细说明如何关注这种关注,您希望找到什么,以及应该如何解决。
          【解决方案6】:

          注意如果您使用的是虚拟环境,请在执行此操作之前激活环境。

          我已经遇到过这个错误。你的代码中没有错误。问题出在 camelot 安装上。

          1 删除已安装的 camelot 版本

          2 使用此命令再次安装。有多种方法可以安装 camelot。请一一试一试

          • pip install camelot-py
          • pip install camelot-py[cv]
          • pip install camelot-py[all]

          3 运行您的代码 >> 我已在此处附加示例代码

          import camelot
          
          data = camelot.read_pdf("test_file.pdf", pages='all')
          print(data)
          

          【讨论】:

          • 它将在 python 编辑器上工作,例如:pycharm
          猜你喜欢
          • 2021-06-20
          • 2023-02-16
          • 1970-01-01
          • 2021-12-10
          • 2018-04-14
          • 2019-02-18
          • 1970-01-01
          • 2020-01-01
          • 2019-07-20
          相关资源
          最近更新 更多