简体   繁体   中英

converting Python Script to EXE with (Tabula) .JavaNotFoundError using Auto Py to EXE

So I made a script that downloads a pdf from the web (via selenium), then converts said pdf table to an excel file (via tabula). I would want to share this script with people in the office however my team does not have any python/programming experience so I decided to convert the python file into an executable using Auto-Py-to-EXE. I then added a file (chromedriver) and it successfully downloaded the file.

For the conversion I used tabula to convert the PDF to a csv and xlsx file. (in the notebook/.py, the conversion worked) but when I converted the .py into an exe and ran the executable I ran into the error below.

  File "tabula\io.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 "tabula\io.py", line 322, in read_pdf
  File "tabula\io.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!

So I tried adding my java path to the environment path by following this link . I've added the C:\Program Files (x86)\Java\jre6\bin to the JAVA_HOME , JAVA , and PATH .

However, now I'm getting this error when I try to execute the EXE file.

Error from tabula-java:
Unable to access jarfile C:\Users\ur7634o\Desktop\erc_scraper\tabula\tabula-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!

Any advice what to do next? It seems the executable cannot read the file? I'm thinking how to make this easy also for the end-users to do this. I was just hoping the end-users can double click some shortcut to initiate the downloading and conversion of a file.

I just ran into this problem today, I tried this and it worked:

  • when you compile your executable, use "One Directory" option
  • after you are done compiling, go to the directory of your tabula package installation, copy that tabula folder into your output folder of auto-py-exe tabula package location

that should work. What's missing is "tabula\tabula-1.0.4-jar-with-dependencies.jar" just as the error indicated. I'm not sure why auto-py-to-exe doesn't bring the tabula package over like the other packages, but I had to bring it over manually.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM