我已经在 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 变量。
我没有评论的声誉,但是
Answer from Java side is empty
但此错误表示无法访问 Java 代码。只是为了验证基本步骤
1) 确保 java 程序正在运行
2) 确保在 Java 代码运行后运行 Python 脚本
3)Java程序一直在运行。
如果您正在执行这两项操作,则问题可能是操作系统可能已在使用端口。
你可以试试
爪哇岛
'GatewayServerBuilder server = new GatewayServerBuilder().javaPort(1001).build()'
'server.start()'
蟒
java = JavaGateway(gateway_parameters=GatewayParameters(port=1001))