使用(Tabula)将Python脚本转换为EXE.使用Auto Py转换为EXE时出现JavaNotFoundErro



所以我制作了一个脚本,从网上下载pdf(通过selenium(,然后将所述pdf表转换为excel文件(通过tabula(。我想和办公室里的人分享这个脚本,但我的团队没有任何python/编程经验,所以我决定使用Auto Py to EXE将python文件转换为可执行文件。然后我添加了一个文件(chromedriver(,它成功地下载了该文件。

对于转换,我使用tabula将PDF转换为csv和xlsx文件。(在笔记本/.py中,转换成功了(但当我将.py转换为exe并运行可执行文件时,我遇到了下面的错误。

File "tabulaio.py", line 80, in _run
File "subprocess.py", line 493, in run
File "subprocess.py", line 858, in __init__
File "subprocess.py", line 1311, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "erc_scraper.py", line 126, in <module>
File "tabulaio.py", line 322, in read_pdf
File "tabulaio.py", line 91, in _run
tabula.errors.JavaNotFoundError: `java` command is not found from this Python process.Please ensure Java is installed and PATH is set for `java`
[24568] Failed to execute script 'erc_scraper' due to unhandled exception!

因此,我尝试通过以下链接将我的java路径添加到环境路径中。我已将C:Program Files (x86)Javajre6bin添加到JAVA_HOMEJAVAPATH中。

然而,现在我在尝试执行EXE文件时遇到了这个错误。

Error from tabula-java:
Unable to access jarfile C:Usersur7634oDesktoperc_scrapertabulatabula-1.0.4-jar-with-dependencies.jar
subprocess.CalledProcessError: Command '['java', '-Dfile.encoding=UTF8', '-jar', 'C:\Users\ur7634o\Desktop\erc_scraper\tabula\tabula-1.0.4-jar-with-dependencies.jar', '--pages', 'all', '--guess', '--format', 'JSON', 'C:\Users\ur7634o\Desktop\ERC Data\pdf\qualified_contestable_customers_20220221-11-09-36.pdf']' 
returned non-zero exit status 1.
[25240] Failed to execute script 'erc_scraper' due to unhandled exception!

有什么建议吗?可执行文件似乎无法读取文件?我正在考虑如何让最终用户也能轻松做到这一点。我只是希望最终用户可以双击一些快捷方式来启动文件的下载和转换。

我今天刚刚遇到这个问题,我尝试了一下,它成功了:

  • 编译可执行文件时,请使用"一个目录";选项
  • 编译完成后,转到tabula软件包安装的目录,将tabula文件夹复制到auto-py-exe的输出文件夹中表格包装位置

这应该有效。缺少的是";tabula\tabula-1.0.4-jar-with-dependences.jar";正如错误所指示的那样。我不知道为什么auto-py-to-exe没有像其他包一样把tabula包带过来,但我不得不手动把它带过来。

最新更新