[已解决]Windows 下使用pyflink出现PyFlink module java.base does not “opens java.lang“ to unnamed module

在Windows上使用PyFlink时遇到一个错误,原因是不兼容JDK19。Flink仅支持JDK8和11。通过安装JDK8并修改PyFlink配置文件flink-conf.yaml,将JDK8路径添加到env.java.home,问题得到解决,程序能正常运行。
摘要由CSDN通过智能技术生成

[已解决]Windows 下使用pyflink出现PyFlink module java.base does not "opens java.lang" to unnamed module

问题复现

最近在用flink在windows环境下敲代码,但是遇到了如下报错:

Traceback (most recent call last):
  File "D:\pythonProject\kafkatest\test.py", line 5, in <module>
    ds.print()
  File "D:\pythonProject\kafkatest\venv\lib\site-packages\pyflink\datastream\data_stream.py", line 883, in print
    j_data_stream_sink = self._align_output_type()._j_data_stream.print()
  File "D:\pythonProject\kafkatest\venv\lib\site-packages\py4j\java_gateway.py", line 1322, in __call__
    return_value = get_return_value(
  File "D:\pythonProject\kafkatest\venv\lib\site-packages\pyflink\util\exceptions.py", line 146, in deco
    return f(*a, **kw)
  File "D:\pythonProject\kafkatest\venv\lib\site-packages\py4j\protocol.py", line 326, in get_return_value
    raise Py4JJavaError(
py4j.protocol.Py4JJavaError: An error occurred while calling o59.print.
: java.lang.reflect.InaccessibleObjectException: Unable to make field private final byte[] java.lang.String.value accessible: module java.base does not "opens java.lang" to unnamed module @799d4f69
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
	at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:180)
	at java.base/java.lang.reflect.Field.setAccessible(Field.java:174)
	at org.apache.flink.api.java.ClosureCleaner.clean(ClosureCleaner.java:106)
	at org.apache.flink.api.java.ClosureCleaner.clean(ClosureCleaner.java:132)
	at org.apache.flink.api.java.ClosureCleaner.clean(ClosureCleaner.java:132)
	at org.apache.flink.api.java.ClosureCleaner.clean(ClosureCleaner.java:69)
	at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.clean(StreamExecutionEnvironment.java:2317)
	at org.apache.flink.streaming.api.datastream.DataStream.clean(DataStream.java:202)
	at org.apache.flink.streaming.api.datastream.DataStream.addSink(DataStream.java:1244)
	at org.apache.flink.streaming.api.datastream.DataStream.print(DataStream.java:937)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
	at java.base/java.lang.reflect.Method.invoke(Method.java:577)
	at org.apache.flink.api.python.shaded.py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
	at org.apache.flink.api.python.shaded.py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:374)
	at org.apache.flink.api.python.shaded.py4j.Gateway.invoke(Gateway.java:282)
	at org.apache.flink.api.python.shaded.py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
	at org.apache.flink.api.python.shaded.py4j.commands.CallCommand.execute(CallCommand.java:79)
	at org.apache.flink.api.python.shaded.py4j.GatewayConnection.run(GatewayConnection.java:238)
	at java.base/java.lang.Thread.run(Thread.java:833)

为了排查问题,我用了一段简单的代码:

from pyflink import datastream
env=datastream.StreamExecutionEnvironment.get_execution_environment()
env.set_parallelism(1)
ds=env.from_collection([1,2,3,4,5,6,7,8,9,10])
ds.print()
env.close()

其实如果没有:

ds.print()

这一行,其实程序是能够正常退出的,然而有了这一行之后,就会报上面提到的错.

报错原因

Flink doesn’t support JDK 19, only 8 and 11.

Flink不支持JDK 19,只支持8和11,所以我们需要使用jdk8

着手解决

找到 jdk1.8.安装好之后,由于笔者不希望改变当前的环境变量,所以找到了pyflink的配置文件夹(一般是\venv\Lib\site-packages\pyflink\conf)
打开flink-conf.yaml ,把JDK1.8路径写入:

env.java.home: E:\java\jdk-1.8

保存之后再运行程序即可:
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值