我已经对我的代码进行了几次测试,每次都运行良好,但现在由于某种原因,它引发了一个奇怪的错误,我会马上停止。我正在使用 tabula 读取一些 pdf 文件,这是出现错误的代码:
for it_page,page in enumerate(pages_id, start=0):
print("page : ", page)
tables = tabula.read_pdf(hermes_pdf_dir + "/" + pdf_name, pages = page)
for i,table in enumerate(tables, start=1):
print( "titre retenu : " + pages_id_titres[it_page][1] + f"_{i}.xlsx")
table.to_excel(os.path.join(folder_name, pages_id_titres[it_page][1] + " p" + str(page) + f"_{i}.xlsx"), index=False)
错误位于以“tables = tabula.read_pdf(...)”开头的行。
最重要的是,这是完整的错误消息:
Traceback (most recent call last):
File "get_pdfs_hermes.py", line 299, in <module>
read_pdf_download_csv(pdf_name2)
File "get_pdfs_hermes.py", line 199, in read_pdf_download_csv
tables = tabula.read_pdf(hermes_pdf_dir + "/" + pdf_name, pages = page)
File "C:\Users\virgi\Python\lib\site-packages\tabula\io.py", line 322, in read_pdf
output = _run(java_options, kwargs, path, encoding)
File "C:\Users\virgi\Python\lib\site-packages\tabula\io.py", line 80, in _run
result = subprocess.run(
File "C:\Users\virgi\Python\lib\subprocess.py", line 512, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['java', '-Dfile.encoding=UTF8', '-jar', 'C:\\Users\\virgi\\Python\\lib\\site-packages\\tabula\\tabula-1.0.4-jar-with-dependencies.jar', '--pages', '104', '--guess', '--format', 'JSON', 'C:\\Users\\virgi\\Desktop\\virgile_stuff\\prog\\banking analyst\\financial_data/data/hermes_data/hermes_2014_rapportannuel_en.pdf']' returned non-zero exit status 1.
它讨论了 java 依赖项(可能是因为 tabula 有 tabula-py 和 tabula-java ?),我发现的与此类错误最相关的问题是应该更新 java,而我的计算机上有最新版本。关于它可能是什么的任何想法?