camelot-dev / camelot

A Python library to extract tabular data from PDFs
https://camelot-py.readthedocs.io
MIT License
2.96k stars 466 forks source link

Export to Excel (camelot CLI interface): TypeError: to_excel() got an unexpected keyword argument 'encoding' #372

Closed ipa-bak closed 1 year ago

ipa-bak commented 1 year ago

Description

I did a fresh install of Camelot in a virtual environment.

Trying to export a PDF to Excel results in TypeError: to_excel() got an unexpected keyword argument 'encoding'

Removing the encoding parameter in core.py line 751 results in another error: AttributeError: 'OpenpyxlWriter' object has no attribute 'save'

It seems some dependency versions mismatch?

pip reports no broken dependencies when running pip check

Steps to reproduce the bug

Steps used to install camelot:

Steps to be used to reproduce behavior:

With in the virtual environment, run

Expected behavior

Camelot processes the file, finds the table on page 1 and exports it to the excel file.

Code

Not applicable, using the provided command line wrapper.

PDF

Not relevant, error is independent of any PDF file.

Screenshots

Not a screenshot, but the Output from Camelot:

$ camelot --output  table.xlsx --format excel  lattice  TestPDF.pdf
2023-05-16T18:23:10 - INFO - Processing page-1
Found 1 tables
Traceback (most recent call last):
  File "/home/seronet/ERF-Table-Hack/bin/camelot", line 8, in <module>
    sys.exit(cli())
  File "/usr/lib/python3/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/seronet/ERF-Table-Hack/lib/python3.8/site-packages/camelot/cli.py", line 213, in lattice
    tables.export(output, f=f, compress=compress)
  File "/home/seronet/ERF-Table-Hack/lib/python3.8/site-packages/camelot/core.py", line 751, in export
    table.df.to_excel(writer, sheet_name=sheet_name, encoding="utf-8")
TypeError: to_excel() got an unexpected keyword argument 'encoding'

After removing the offending encoding="utf-8" I get:

$ camelot --output  table.xlsx --format excel  lattice  TestPDF.pdf
2023-05-16T18:38:47 - INFO - Processing page-1
Found 1 tables
/usr/lib/python3/dist-packages/requests/__init__.py:89: RequestsDependencyWarning: urllib3 (1.25.8) or chardet (5.1.0) doesn't match a supported version!
  warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "
Traceback (most recent call last):
  File "/home/seronet/ERF-Table-Hack/bin/camelot", line 8, in <module>
    sys.exit(cli())
  File "/home/seronet/ERF-Table-Hack/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/seronet/ERF-Table-Hack/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/seronet/ERF-Table-Hack/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/seronet/ERF-Table-Hack/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/seronet/ERF-Table-Hack/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/seronet/ERF-Table-Hack/lib/python3.8/site-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/home/seronet/ERF-Table-Hack/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/seronet/ERF-Table-Hack/lib/python3.8/site-packages/camelot/cli.py", line 213, in lattice
    tables.export(output, f=f, compress=compress)
  File "/home/seronet/ERF-Table-Hack/lib/python3.8/site-packages/camelot/core.py", line 752, in export
    writer.save()
AttributeError: 'OpenpyxlWriter' object has no attribute 'save'

Environment

Additional context

None I am aware of. Feel free to ask (@ mention) if you need more info.