3

I created a script to extract data from a pdf using tabula-py and PyPDF2. When I run my program through Jupyter-notebook and from the cmd, it works perfectly. After converting it to executable with pyinstaller, I get this error:

Error: Unable to access jarfile 
E:\Users\paulhong\AppData\Local\Temp\_MEI175522\tabula\tabula-1.0.2-jar-with-dependencies.jar
Error:
Traceback (most recent call last):
File "test.py", line 115, in <module>

File "test.py", line 32, in extractDataDik
tempDf = tabula.read_pdf(file, area = (72, 252, 115.2, 352.8), guess=False, pages='1')
File "site-packages\tabula\wrapper.py", line 108, in read_pdf
File "subprocess.py", line 395, in check_output
File "subprocess.py", line 487, in run
subprocess.CalledProcessError: Command '['java', '-Dfile.encoding=UTF8', '-jar', 
'E:\\Users\\paulhong\\AppData\\Local\\Temp\\_MEI175522\\tabula\\tabula-1.0.2-jar-with-dependencies.jar', '--pages', '1', '--area', 
'72,252,115.2,352.8', 'E:\\Users\\paulhong\\Desktop\\Purchase Order 
2\\SKM_C45819060508450 (003).pdf']' returned non-zero exit status 1. [47140] Failed to execute script test

I also couldn't find the folder _MEI175522 on the specified path.

My python version is 3.7.1 Java version is 1.8 pyinstaller version is 3.4 Tabula-py is the latest version

How can I fix this issue?

paul
  • 121
  • 1
  • 10

3 Answers3

6

I had a similar problem, and I was able to solve it using the solution at this link: Unable to access jarfile 'tabula-1.0.2-jar-with-dependencies.jar'

I built my app within a virtual environment, so I added a tabula folder with the tabula-1.0.2-jar-with-dependencies.jar file to my site-packages folder. Running the command pyinstaller --add-data apps\Lib\site-packages\tabula\tabula-1.0.2-jar-with-dependencies.jar;tabula --onefile Table_OCR.py builds the executable correctly for me.

alleycat10
  • 76
  • 1
  • 2
  • I was using GUI version of pyinstaller called as "auto-py-to-exe". I too faced same issue. The above solution worked. thanks @alleycat10 – Deepak Harish Sep 16 '21 at 12:43
1

It looks like the tabula module hasn't been copied to the dist folder of your executable, in my experience this is a common problem with pyinstaller it can often miss packages in the python directory.

Go to the dist folder and check if the tabula folder is there, if it's not then you'll need to copy it over.

Go to your python directory, it should be somewhere like this: C:\Users\<user_name>\AppData\Local\Programs\Python\Python37-32\Lib\site-packages

Copy over any packages from here that need to be in the dist folder

EcSync
  • 842
  • 1
  • 6
  • 20
  • 1
    Sorry for the late reply, I created a stand alone executable using "--onefile" option. I think in this case you would not need to have a tabula folder within dist folder, how would I fix for stand alone executable? Do I need to specify hooks? – paul Jun 24 '19 at 23:48
0

I found this GitHub post to be helpful.

Essentially:

1- Locate the tabula jar file on your system. The path may look something like this:

C:\ProgramData\Miniconda3\Lib\site-packages\tabula\tabula-1.0.5-jar-with-dependencies.jar

2- Use the --add-file option when running pyinstaller:

pyinstaller your_file.py --add-data "C:\ProgramData\Miniconda3\Lib\site-packages\tabula\tabula-1.0.5-jar-with-dependencies.jar;tabula"

(Notice the ;tabula appended to the path. It is ;tabula for Windows, :tabula for Linux).

Anis R.
  • 6,656
  • 2
  • 15
  • 37