【问题标题】:regarding a py4j exception关于 py4j 异常
【发布时间】:2019-01-11 15:04:04
【问题描述】:

我在 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 变量。

【问题讨论】:

    标签: centos py4j


    【解决方案1】:

    我没有评论的声誉,但是

    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))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-28
      • 1970-01-01
      • 1970-01-01
      • 2013-06-22
      • 2013-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多