AdarshVShetty
AdarshVShetty

Reputation: 33

Python flask application on pivotal cloud foundry throws java error

I have a python flask application which uses tabula internally to extract tables from pdf files.After I do 'cf push' and run the application on PCF,i load the pdf file to the application to read the table. When the app tries to extract the tabular data,I get the below error.

2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] [2020-08-10 08:08:40,134] ERROR in app: Exception on / [POST]
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] Traceback (most recent call last):
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] File "/home/vcap/deps/0/python/lib/python3.8/site-packages/tabula/io.py", line 80, in _run
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] result = subprocess.run(
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] File "/home/vcap/deps/0/python/lib/python3.8/subprocess.py", line 489, in run
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] with Popen(*popenargs, **kwargs) as process:
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] File "/home/vcap/deps/0/python/lib/python3.8/subprocess.py", line 854, in __init__
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] self._execute_child(args, executable, preexec_fn, close_fds,
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] File "/home/vcap/deps/0/python/lib/python3.8/subprocess.py", line 1702, in _execute_child
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] raise child_exception_type(errno_num, err_msg, err_filename)
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] FileNotFoundError: [Errno 2] No such file or directory: 'java'
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] During handling of the above exception, another exception occurred:
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] Traceback (most recent call last):
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] File "/home/vcap/deps/0/python/lib/python3.8/site-packages/flask/app.py", line 2446, in wsgi_app
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] response = self.full_dispatch_request()
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] File "/home/vcap/deps/0/python/lib/python3.8/site-packages/flask/app.py", line 1951, in full_dispatch_request
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] rv = self.handle_user_exception(e)
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] File "/home/vcap/deps/0/python/lib/python3.8/site-packages/flask/app.py", line 1820, in handle_user_exception
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] reraise(exc_type, exc_value, tb)
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] File "/home/vcap/deps/0/python/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] raise value
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] File "/home/vcap/deps/0/python/lib/python3.8/site-packages/flask/app.py", line 1949, in full_dispatch_request
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] rv = self.dispatch_request()
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] File "/home/vcap/deps/0/python/lib/python3.8/site-packages/flask/app.py", line 1935, in dispatch_request
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] return self.view_functions[rule.endpoint](**req.view_args)
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] File "app.py", line 55, in index
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] wireListDF = pdfExtractorOBJ.getWireListDataFrame()
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] File "/home/vcap/app/WireHarnessPDFExtractor.py", line 158, in getWireListDataFrame
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] self.readBTPPDF()
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] File "/home/vcap/app/WireHarnessPDFExtractor.py", line 31, in readBTPPDF
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] df = tabula.read_pdf(self.pdf_path, pages='all', stream=True ,guess=True, encoding="utf-8",
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] File "/home/vcap/deps/0/python/lib/python3.8/site-packages/tabula/io.py", line 322, in read_pdf
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] output = _run(java_options, kwargs, path, encoding)
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] File "/home/vcap/deps/0/python/lib/python3.8/site-packages/tabula/io.py", line 91, in _run
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] raise JavaNotFoundError(JAVA_NOT_FOUND_ERROR)
2020-08-10T13:38:40.135+05:30 [APP/PROC/WEB/0] [ERR] tabula.errors.JavaNotFoundError: `java` command is not found from this Python process.Please ensure Java is installed and PATH is set for `java`
2020-08-10T13:38:40.136+05:30 [APP/PROC/WEB/0] [ERR] 10.255.10.112 - - [10/Aug/2020 08:08:40] "[35m[1mPOST / HTTP/1.1[0m" 500 -

I know tabula has java dependencies, any suggestions on how to have the setup for the python flask application with tabula so that it can be used on PCF platform.

Upvotes: 0

Views: 401

Answers (2)

Daniel Mikusa
Daniel Mikusa

Reputation: 15006

The highlights:

  • You need multiple buildpacks, one for Java and one for Python
  • You want to use apt-buildpack, not the Java buildpack though
  • You need to set PATH to point to the location where the apt-buildpack installs Java (or have your app look for Java in this specific place)
  • You can set PATH in a .profile file.

All of this is explained in my answer to this similar question.

Upvotes: 0

awadhesh pathak
awadhesh pathak

Reputation: 121

This is a java path error. Your python runtime is not able to find java at all. You need to ensure that your export java in your export path variables. If you are running this process on linux, you can export export PATH=<your java bin dir>:$PATH

Upvotes: 1

Related Questions