gpt4 book ai didi

python - 由于 ImportError : No module named 'resource' ,Spark Release 2.4.0 无法在 win7 上运行

转载 作者:太空宇宙 更新时间:2023-11-04 02:12:44 28 4
gpt4 key购买 nike

我尝试在我的电脑上安装 Spark Release 2.4.0,系统是 win7_x64。

然而,当我尝试运行简单的代码来检查 spark 是否准备好工作时:代码:

import os
from pyspark import SparkConf, SparkContext
conf = SparkConf().setMaster('local[*]').setAppName('word_count')
sc = SparkContext(conf=conf)
d = ['a b c d', 'b c d e', 'c d e f']
d_rdd = sc.parallelize(d)
rdd_res = d_rdd.flatMap(lambda x: x.split(' ')).map(lambda word: (word, 1)).reduceByKey(lambda a, b: a+b)
print(rdd_res)
print(rdd_res.collect())

我收到这个错误:

error1

我打开 worker.py 文件来检查代码。

我发现,在 2.4.0 版本中,代码是:

worker.py v2.4.0

但是在2.3.2版本中,代码是:

worker.py v2.3.2

然后我重新安装 spark-2.3.2-bin-hadoop2.7 ,代码工作正常。

此外,我发现了这个问题: ImportError: No module named 'resource'

所以,我认为 spark-2.4.0-bin-hadoop2.7 不能在 win7 中工作,因为导入worker.py 中的资源模块,这是一个 Unix 特定的包。

我希望有人能在 spark 中解决这个问题。

最佳答案

我遇到了这个错误,我在 Windows 上安装了 spark 2.4.0、jdk 11 和 kafka 2.11。我能够通过这样做来解决这个问题 - 1) 光盘 spark_home\python\lib
例如。 cd C:\myprograms\spark-2.4.0-bin-hadoop2.7\python
2) 解压pyspark.zip
3) 编辑 worker.py ,注释掉 'import resource' 和下面的 para 并保存文件。这一段只是附加的,不是核心代码,注释掉就好了。
4) 删除旧的 pyspark.zip 并创建新的 zip。
5) 在jupyter notebook中重启内核。


commented para in worker.py -

    # set up memory limits
#memory_limit_mb = int(os.environ.get('PYSPARK_EXECUTOR_MEMORY_MB', "-1"))
#total_memory = resource.RLIMIT_AS
#try:
# if memory_limit_mb > 0:
#(soft_limit, hard_limit) = resource.getrlimit(total_memory)
#msg = "Current mem limits: {0} of max {1}\n".format(soft_limit, hard_limit)
#print(msg, file=sys.stderr)

# convert to bytes
#new_limit = memory_limit_mb * 1024 * 1024

#if soft_limit == resource.RLIM_INFINITY or new_limit < soft_limit:
# msg = "Setting mem limits to {0} of max {1}\n".format(new_limit, new_limit)
# print(msg, file=sys.stderr)
# resource.setrlimit(total_memory, (new_limit, new_limit))

#except (resource.error, OSError, ValueError) as e:
# # not all systems support resource limits, so warn instead of failing
# print("WARN: Failed to set memory limit: {0}\n".format(e), file=sys.stderr)

关于python - 由于 ImportError : No module named 'resource' ,Spark Release 2.4.0 无法在 win7 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53375128/

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