centos - 关于 py4j 异常

标签 centos py4j

我在 CentOS 上安装了 Java 11 和 Python 3。尝试运行在 Windows 环境下运行良好的代码。得到这个异常(exception):

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程序一直在运行。

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

你可以试试

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

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

关于centos - 关于 py4j 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54149088/

相关文章:

linux - 运行 SSH 命令并从 WinSCP 退出而不中断命令

linux - 专用 memcached 虚拟集群的最小/理想 memcached 堆栈是多少

linux-kernel - 旧内核模块在重启后仍然存在

apache-spark - 如何从 PySpark 中的 JavaSparkContext 获取 SparkContext?

python - 从 Python 连接和测试 JDBC 驱动程序

amazon-web-services - 已断开 没有可用的受支持的身份验证方法(服务器发送公钥) 发送公钥 gssapi key 和麦克风

linux - libxml2.so.2 : cannot open shared object file: No such file or directory

java - Py4j 在服务器中运行应用程序时出现异常

Python -> Py4j -> Spark -> Cassandra