jpmml / jpmml-evaluator-python

PMML evaluator library for Python
GNU Affero General Public License v3.0
20 stars 9 forks source link

py4j.protocol.Py4JNetworkError: Answer from Java side is empty #2

Closed Harpsichord1207 closed 5 years ago

Harpsichord1207 commented 5 years ago

I copied the code in readme except replace the pmml file and csv file , and then raise a error.

Code:

from jpmml_evaluator import launch_gateway

gateway = launch_gateway()

from jpmml_evaluator import Evaluator, LoadingModelEvaluatorBuilder

evaluatorBuilder = LoadingModelEvaluatorBuilder(gateway) \
    .setLocatable(True) \
    .loadFile("model.pmml")

evaluator = evaluatorBuilder.build() \
    .verify()

import pandas

arguments_df = pandas.read_csv("Churn.csv", sep = ",")

results_df = evaluator.evaluateAll(arguments_df)
print(results_df)

gateway.shutdown()

Error:

E:\MachineLearning\venv\Scripts\python.exe E:/MachineLearning/GeekWeek/main.py
ERROR:root:Exception while sending command.
Traceback (most recent call last):
  File "E:\MachineLearning\venv\lib\site-packages\py4j\java_gateway.py", line 1188, in send_command
    raise Py4JNetworkError("Answer from Java side is empty")
py4j.protocol.Py4JNetworkError: Answer from Java side is empty

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\MachineLearning\venv\lib\site-packages\py4j\java_gateway.py", line 1014, in send_command
    response = connection.send_command(command)
  File "E:\MachineLearning\venv\lib\site-packages\py4j\java_gateway.py", line 1193, in send_command
    "Error while receiving", e, proto.ERROR_ON_RECEIVE)
py4j.protocol.Py4JNetworkError: Error while receiving
Traceback (most recent call last):
  File "E:/MachineLearning/GeekWeek/main.py", line 8, in <module>
    .setLocatable(True) \
  File "E:\MachineLearning\venv\lib\site-packages\jpmml_evaluator\__init__.py", line 110, in setLocatable
    self.javaModelEvaluatorBuilder.setLocatable(locatable)
  File "E:\MachineLearning\venv\lib\site-packages\py4j\java_gateway.py", line 1286, in __call__
    answer, self.gateway_client, self.target_id, self.name)
  File "E:\MachineLearning\venv\lib\site-packages\py4j\protocol.py", line 336, in get_return_value
    format(target_id, ".", name))
py4j.protocol.Py4JError: An error occurred while calling o0.setLocatable

Process finished with exit code 1
vruusmann commented 5 years ago

py4j.protocol.Py4JNetworkError: Answer from Java side is empty

This is a generic Py4J layer error. The execution gets stuck when launching the Py4J gateway, because there doesn't seem to be a Java installation available.

Do you have Java 1.8 (or newer) installed and available on system path? To test it, open a command prompt, and type java -version. What do you see?

Harpsichord1207 commented 5 years ago

@vruusmann Thanks for replying, Yes I have a java, maybe the version is incompatible?

$ java -version
java version "11.0.2" 2019-01-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode)
vruusmann commented 5 years ago

Version 11(.0.2) is definitely newer/greater than the minimum required version 8.

There shouldn't be any problems with Java 11 from the JPMML-Evaluator library perspective. But perhaps there are some issues with the Py4J "carrier layer" perspective.

You should try making a parallel Java 8 installation into your computer. Then, export to the location of the Java 8 installation as JAVA_HOME environment variable (AFAIK, this is how Py4J locates the Java version to use), and try again.

vruusmann commented 5 years ago

Thanks, I solved the problem by changing all "Interger" to "Double" in the pmml file.

@Harpsichord1207 This is no real solution. One cannot go on manually correcting PMML files. You should really inform the KNIME team about this issue, and ask them to fix their software.

Harpsichord1207 commented 5 years ago

Version 11(.0.2) is definitely newer/greater than the minimum required version 8.

There shouldn't be any problems with Java 11 from the JPMML-Evaluator library perspective. But perhaps there are some issues with the Py4J "carrier layer" perspective.

You should try making a parallel Java 8 installation into your computer. Then, export to the location of the Java 8 installation as JAVA_HOME environment variable (AFAIK, this is how Py4J locates the Java version to use), and try again.

I install a Java 8, and get the same error:

$ java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
Harpsichord1207 commented 5 years ago

Thanks, I solved the problem by changing all "Interger" to "Double" in the pmml file.

@Harpsichord1207 This is no real solution. One cannot go on manually correcting PMML files. You should really inform the KNIME team about this issue, and ask them to fix their software.

Thanks, I'll feed back this issue to KNIME team.

vruusmann commented 5 years ago

It's now possible to choose between PyJNIus and Py4J backends (see the README file).

Please give the PyJNIus backend a try (if the Py4J backend keeps failing).