Homebrew安装Apache Spark后执行spark-submit/pyspark报错找不到spark-class
解决Homebrew安装Apache Spark后spark-submit/pyspark报错找不到spark-class的问题
问题根源
你遇到的错误是因为spark-submit脚本第27行硬编码了绝对路径/bin/spark-class,但Homebrew安装的Apache Spark的spark-class实际存放在Spark安装目录的bin子文件夹下,而非系统根目录的/bin。
解决方案
方案1:修改spark-submit脚本路径
- 打开
spark-submit脚本进行编辑:open -e /opt/homebrew/bin/spark-submit - 找到第27行,将
/bin/spark-class修改为相对路径bin/spark-class,或者替换为Spark安装目录下的绝对路径(先通过ls /opt/homebrew/Cellar/apache-spark/查看你的Spark版本号,比如3.5.0,那么路径就是/opt/homebrew/Cellar/apache-spark/3.5.0/libexec/bin/spark-class) - 保存脚本后,重新执行
spark-submit或pyspark --master local[2]测试。
方案2:配置SPARK_HOME环境变量
- 确定Spark的实际安装路径:
先查看已安装的Spark版本:
假设版本为3.5.0,那么SPARK_HOME路径为ls /opt/homebrew/Cellar/apache-spark//opt/homebrew/Cellar/apache-spark/3.5.0/libexec - 将SPARK_HOME添加到环境变量配置文件(如果用zsh则编辑
~/.zshrc,bash则编辑~/.bash_profile):echo 'export SPARK_HOME=/opt/homebrew/Cellar/apache-spark/3.5.0/libexec' >> ~/.zshrc echo 'export PATH=$SPARK_HOME/bin:$PATH' >> ~/.zshrc - 刷新环境变量使配置生效:
source ~/.zshrc - 之后直接运行
spark-submit或pyspark --master local[2]即可正常使用。
方案3:重新链接Homebrew包
如果是Homebrew的软链接出现问题,尝试重新链接:
brew link apache-spark
内容的提问来源于stack exchange,提问作者deepak marathe
相关产品推荐
相关产品推荐

