gpt4 book ai didi

apache-spark - AWS EMR - ModuleNotFoundError : No module named 'pyarrow'

转载 作者:行者123 更新时间:2023-12-04 13:18:29 25 4
gpt4 key购买 nike

我在使用 Apache Arrow Spark 集成时遇到了这个问题。

使用带有 Spark 2.4.3 的 AWS EMR

在本地 spark 单机实例和 Cloudera 集群上测试了这个问题,一切正常。

在 spark-env.sh 中设置这些

export PYSPARK_PYTHON=python3
export PYSPARK_PYTHON_DRIVER=python3

在 Spark shell 中证实了这一点

spark.version
2.4.3
sc.pythonExec
python3
SC.pythonVer
python3

使用 apache 箭头集成运行基本的 pandas_udf 会导致错误

from pyspark.sql.functions import pandas_udf, PandasUDFType

df = spark.createDataFrame(
[(1, 1.0), (1, 2.0), (2, 3.0), (2, 5.0), (2, 10.0)],
("id", "v"))

@pandas_udf("id long, v double", PandasUDFType.GROUPED_MAP)
def subtract_mean(pdf):
# pdf is a pandas.DataFrame
v = pdf.v
return pdf.assign(v=v - v.mean())

df.groupby("id").apply(subtract_mean).show()

aws emr 上的错误 [在 cloudera 和本地机器上不会出错]

ModuleNotFoundError: No module named 'pyarrow'

at org.apache.spark.api.python.BasePythonRunner$ReaderIterator.handlePythonException(PythonRunner.scala:452)
at org.apache.spark.sql.execution.python.ArrowPythonRunner$$anon$1.read(ArrowPythonRunner.scala:172)
at org.apache.spark.sql.execution.python.ArrowPythonRunner$$anon$1.read(ArrowPythonRunner.scala:122)
at org.apache.spark.api.python.BasePythonRunner$ReaderIterator.hasNext(PythonRunner.scala:406)
at org.apache.spark.InterruptibleIterator.hasNext(InterruptibleIterator.scala:37)
at scala.collection.Iterator$$anon$12.hasNext(Iterator.scala:440)
at scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:409)
at org.apache.spark.sql.catalyst.expressions.GeneratedClass$GeneratedIteratorForCodegenStage3.processNext(Unknown Source)
at org.apache.spark.sql.execution.BufferedRowIterator.hasNext(BufferedRowIterator.java:43)
at org.apache.spark.sql.execution.WholeStageCodegenExec$$anonfun$13$$anon$1.hasNext(WholeStageCodegenExec.scala:636)
at org.apache.spark.sql.execution.SparkPlan$$anonfun$2.apply(SparkPlan.scala:291)
at org.apache.spark.sql.execution.SparkPlan$$anonfun$2.apply(SparkPlan.scala:283)
at org.apache.spark.rdd.RDD$$anonfun$mapPartitionsInternal$1$$anonfun$apply$24.apply(RDD.scala:836)
at org.apache.spark.rdd.RDD$$anonfun$mapPartitionsInternal$1$$anonfun$apply$24.apply(RDD.scala:836)
at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:52)
at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:324)
at org.apache.spark.rdd.RDD.iterator(RDD.scala:288)
at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:52)
at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:324)
at org.apache.spark.rdd.RDD.iterator(RDD.scala:288)
at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:90)
at org.apache.spark.scheduler.Task.run(Task.scala:121)
at org.apache.spark.executor.Executor$TaskRunner$$anonfun$10.apply(Executor.scala:408)
at org.apache.spark.util.Utils$.tryWithSafeFinally(Utils.scala:1360)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:414)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

任何人都知道发生了什么?一些可能的想法......

PYTHONPATH 是否会导致问题,因为我没有使用 anaconda ?

和Spark版和Arrow版有关系吗?

这是最奇怪的事情,因为我在所有 3 个平台 [本地桌面、cloudera、emr] 中使用相同的版本,只有 EMR 不起作用......

我登录了所有 4 个 EMR EC2 数据节点并测试我可以导入 pyarrow它工作得很好,但在尝试与 spark 一起使用时就不行了。

# test

import numpy as np
import pandas as pd
import pyarrow as pa
df = pd.DataFrame({'one': [20, np.nan, 2.5],'two': ['january', 'february', 'march'],'three': [True, False, True]},index=list('abc'))
table = pa.Table.from_pandas(df)

最佳答案

在 EMR 中,python3 默认不解析。你必须让它明确。一种方法是通过 config.json创建集群时的文件。它在 Edit software settings 中可用AWS EMR UI 中的部分。一个示例 json 文件看起来像这样。

[
{
"Classification": "spark-env",
"Configurations": [
{
"Classification": "export",
"Properties": {
"PYSPARK_PYTHON": "/usr/bin/python3"
}
}
]
},
{
"Classification": "yarn-env",
"Properties": {},
"Configurations": [
{
"Classification": "export",
"Properties": {
"PYSPARK_PYTHON": "/usr/bin/python3"
}
}
]
}
]

您还需要拥有 pyarrow模块安装在所有核心节点,而不仅仅是主节点。为此,您可以在 AWS 中创建集群时使用引导脚本。同样,示例引导脚本可以像这样简单:
#!/bin/bash
sudo python3 -m pip install pyarrow==0.13.0

关于apache-spark - AWS EMR - ModuleNotFoundError : No module named 'pyarrow' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57315030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com