关于py4j例外

时间:2019-01-11 15:04:05

标签: centos py4j

我已经在CentOS上安装了Java 11和Python 3。尝试运行在Windows环境下运行良好的代码。得到此异常:

ERROR:root:Exception while sending command.
Traceback (most recent call last):
File "/usr/lib/python3.4/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 "/usr/lib/python3.4/site-packages/py4j/java_gateway.py", line 1014, in send_command
response = connection.send_command(command)
File "/usr/lib/python3.4/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 "WordInformation.py", line 493, in 
status = read_from_source("../Corpora/Bhandarkar Oriental Research Books") 

File "WordInformation.py", line 473, in read_from_source
author, year)
File "WordInformation.py", line 381, in fetch_from_hwn
return read_store_properties(word, file, sentence, source, category, author, 
year);
File "WordInformation.py", line 79, in read_store_properties
properties["synsets"] = get_other_props(word)
File "WordInformation.py", line 226, in get_other_props
output = gateway.jvm.Properties.getProperties(word)
File "/usr/lib/python3.4/site-packages/py4j/java_gateway.py", line 1286, in 
call
answer, self.gateway_client, self.target_id, self.name)
File "/usr/lib/python3.4/site-packages/py4j/protocol.py", line 336, in 
get_return_value
format(target_id, ".", name))
py4j.protocol.Py4JError: An error occurred while calling 
z:in.ac.iitb.cfilt.jhwnl.examples.Properties.getProperties

按以下方式初始化网关: gateway = JavaGateway.launch_gateway(classpath="/home/gayatri/Code/hindiwn.jar") 这是由于某种依赖性吗?我已经设置了JAVA_HOME并更新了PATH变量。

1 个答案:

答案 0 :(得分:0)

我没有评论的名声,但是

Answer from Java side is empty

但是此错误表明Java代码不可访问。 只是为了验证基本步骤

1)确保Java程序正在运行

2)确保在Java代码运行之后运行Python脚本

3)Java程序一直在运行。

如果您正在做这两件事,那么可能是操作系统可能已经在使用端口。

您可以尝试

Java

'GatewayServerBuilder server = new GatewayServerBuilder().javaPort(1001).build()'
'server.start()'

Python

java = JavaGateway(gateway_parameters=GatewayParameters(port=1001))