pyflink udf 提交到本地集群执行报错No module named pyflink

在Mac环境下使用Flink 1.11.2执行pyflink时遇到模块未找到错误。由于系统存在多个Python环境,导致默认环境中缺少pyflink。尝试通过指定Python执行环境解决,但又出现不支持pickle协议5的错误。参考相关文档,最终通过安装`pickle5`库成功解决问题。
摘要由CSDN通过智能技术生成

背景

mac环境 flink 1.11.2 执行pyflink
flink run -py /Users/haozhang/from_hive_to_mysql.py

pyflink udf大概内容

@udf(input_types=[DataTypes.ARRAY(DataTypes.INT())], result_type=DataTypes.STRING())
def changeIntArrayToString(data):
    return str(data)

t_env.execute_sql("select id,name,changeIntArrayToString(hobby) as hobby2 from hst1int").print()

报错

Caused by: java.io.IOException: Failed to execute the command: python -c
import pyflink;import
os;print(os.path.join(os.path.abspath(os.path.dirname(pyflink.__file__)),
'bin'))
output: Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named pyflink

原因分析

系统中有多个python执行环境,默认的系统中的执行环境不带pyflink ,所以提交指令带上本地执行器:

flink run -py /Users/haozhang/work/project/feature-operator/flink-operator/python_codes/examples/stream/from_hive_to_mysql.py -pyexec /Users/haozhang/opt/anaconda3/envs/feature-operator/bin/python

参考文档:http://apache-flink.147419.n8.nabble.com/python-udf-td7198.html

指定python执行环境后接着报错:

File "/Applications/flink-1.11.2/opt/python/pyflink.zip/pyflink/table/table_result.py", line 144, in print
  File "/Applications/flink-1.11.2/opt/python/py4j-0.10.8.1-src.zip/py4j/java_gateway.py", line 1285, in __call__
  File "/Applications/flink-1.11.2/opt/python/pyflink.zip/pyflink/util/exceptions.py", line 147, in deco
  File "/Applications/flink-1.11.2/opt/python/py4j-0.10.8.1-src.zip/py4j/protocol.py", line 326, in get_return_value
py4j.protocol.Py4JJavaError: An error occurred while calling o132.print.
: java.lang.RuntimeException: Failed to fetch next result
	at org.apache.flink.streaming.api.operators.collect.CollectResultIterator.nextResultFromFetcher(CollectResultIterator.java:92)
	at org.apache.flink.streaming.api.operators.collect.CollectResultIterator.hasNext(CollectResultIterator.java:63)
	at org.apache.flink.table.utils.PrintUtils.printAsTableauForm(PrintUtils.java:144)
	at org.apache.flink.table.api.internal.TableResultImpl.print(TableResultImpl.java:98)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	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:357)
	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.lang.Thread.run(Thread.java:748)
Caused by: java.io.IOException: Failed to fetch job execution result
	at org.apache.flink.streaming.api.operators.collect.CollectResultFetcher.getAccumulatorResults(CollectResultFetcher.java:178)
	at org.apache.flink.streaming.api.operators.collect.CollectResultFetcher.next(CollectResultFetcher.java:128)
	at org.apache.flink.streaming.api.operators.collect.CollectResultIterator.nextResultFromFetcher(CollectResultIterator.java:89)
	... 14 more
Caused by: java.util.concurrent.ExecutionException: org.apache.flink.client.program.ProgramInvocationException: Job failed (JobID: 935c9e49e1c012319c4bcaecd43e6d3a)
	at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357)
	at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1928)
	at org.apache.flink.streaming.api.operators.collect.CollectResultFetcher.getAccumulatorResults(CollectResultFetcher.java:175)
	... 16 more
Caused by: org.apache.flink.client.program.ProgramInvocationException: Job failed (JobID: 935c9e49e1c012319c4bcaecd43e6d3a)
	at org.apache.flink.client
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

house.zhang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值