PySpark(Spark3.0)

本文详细介绍了如何在Centos7环境下配置PySpark3.0,包括安装Python3、配置环境变量,并通过PySparkShell运行WordCount示例。此外,还讲述了在Pycharm中创建PySpark项目并解决运行时遇到的问题,如环境变量配置和HDFS权限设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

PySpark(Spark3.0)

PySpark简单来说就是Spark提供的Python编程API,包括交互式的PySpark shell和非交互式的Python程序。

1.环境

  • Spark3.0
  • Hadooop3.2
  • Centos7
  • Python3.6.8
  • Pycharm
  • Windos10

其中值得注意的是Python的版本必须是3.6+,以下是Spark官网的说明
在这里插入图片描述

前提

​ Spark3.0的集群已经搭建完毕,本文使用的是Standalone模式的集群

​ Hadoop3.2分布式集群搭建完毕

2.PySpark shell

2.1安装python3

yum install -y python3

PS:集群中的所有节点都要安装

# 验证
python3 -V

在这里插入图片描述

2.1配置环境变量

PySparkShell的启动需要配置SPARK_HOMEPYSPARK_PYTHON这两个环境变量,如果不配置就会使用系统自带的Python2.7.5,由于Python2和Python3的语法是不兼容的,这样就会出现问题,导致PySPark无法使用。

vi /etc/profile
export SPARK_HOME=/opt/spark-3.0.2
export PATH=$PATH:$SPARK_HOME/bin
export PYSPARK_PYTHON=python3
# 刷新环境变量
source /etc/profile

在这里插入图片描述
注意:根据自己时间的路径配置

2.2使用PySpark Shell

# 启动Spark
/opt/spark-3.0.2/sbin/start-all.sh
# 在Spark的bin目录中有pySpark的脚本 直接全路径执行
/opt/spark-3.0.2/bin/pyspark
# 使用如下命令退出PySpark Shell
exit()

在这里插入图片描述

如果Python的版本不是3.6+ 那就需要检查环境变量配置是否正确以及环境变量是否生效
使用source /etc/profile 使环境变量的配置生效
注意:这样启动只是一个Local模式的PySpark Shell

2.3PySpark

About This Book, Learn why and how you can efficiently use Python to process data and build machine learning models in Apache Spark 2.0Develop and deploy efficient, scalable real-time Spark solutionsTake your understanding of using Spark with Python to the next level with this jump start guide, Who This Book Is For, If you are a Python developer who wants to learn about the Apache Spark 2.0 ecosystem, this book is for you. A firm understanding of Python is expected to get the best out of the book. Familiarity with Spark would be useful, but is not mandatory., What You Will Learn, Learn about Apache Spark and the Spark 2.0 architectureBuild and interact with Spark DataFrames using Spark SQLLearn how to solve graph and deep learning problems using GraphFrames and TensorFrames respectivelyRead, transform, and understand data and use it to train machine learning modelsBuild machine learning models with MLlib and MLLearn how to submit your applications programmatically using spark-submitDeploy locally built applications to a cluster, In Detail, Apache Spark is an open source framework for efficient cluster computing with a strong interface for data parallelism and fault tolerance. This book will show you how to leverage the power of Python and put it to use in the Spark ecosystem. You will start by getting a firm understanding of the Spark 2.0 architecture and how to set up a Python environment for Spark., You will get familiar with the modules available in PySpark. You will learn how to abstract data with RDDs and DataFrames and understand the streaming capabilities of PySpark. Also, you will get a thorough overview of machine learning capabilities of PySpark using ML and MLlib, graph processing using GraphFrames, and polyglot persistence using Blaze. Finally, you will learn how to deploy your applications to the cloud using the spark-submit command., By the end of this book, you will have established a firm understanding of the Spark Python API and how it can be used t
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

小宇0926

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

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

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

打赏作者

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

抵扣说明:

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

余额充值