我正在尝试使用 camelot 从 pdf 中提取表格,但出现此属性错误。能否请你帮忙?
import camelot
import pandas as pd
pdf = camelot.read_pdf("Gordian.pdf")
----> 1 pdf = camelot.read_pdf("Gordian.pdf") 中的 AttributeError Traceback (最近一次调用最后一次)
AttributeError:模块“camelot”没有属性“read_pdf”
我正在尝试使用 camelot 从 pdf 中提取表格,但出现此属性错误。能否请你帮忙?
import camelot
import pandas as pd
pdf = camelot.read_pdf("Gordian.pdf")
----> 1 pdf = camelot.read_pdf("Gordian.pdf") 中的 AttributeError Traceback (最近一次调用最后一次)
AttributeError:模块“camelot”没有属性“read_pdf”
注意:如果您使用的是虚拟环境,请在执行此操作之前激活环境。
我已经遇到了这个错误。您的代码中没有错误。问题出在 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)
请检查您的机器上是否安装了 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
我放弃了尝试让 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]
试试这个:import camelot.io as camelot
这对我有用。
Here's the link with full installation steps: https://camelot-py.readthedocs.io/en/master/user/install.html#using-pip
After you install
pip install camelot-py[cv]
Write this:
import camelot.io as camelot
下载库时请注意下载位置。因为你下载的库可能已经保存在另一个 Python 版本中