2.安装Spark与Python练习

一、安装Spark

1. 检查基础环境hadoop,jdk

image
未配置好hadoop,去~/.bashrc添加环境变量
export PATH=$PATH:$HADOOP_HOME/sbin

2. 环境变量

添加spark环境变量

export SPARK_HOME=/usr/local/spark
export PYTHONPATH=$SPARK_HOME/python:$SPARK_HOME/python/lib/py4j-0.10.9-src.zip:PYTHONPATH
export PYSPARK_PYTHON=python3
export PATH=$PATH:$SPARK_HOME/bin

image

3. 试运行Python代码

image

二、Python编程练习:英文文本的词频统计

1. 准备文本文件

image

2. 准备python代码

path='/home/hadoop/wc/f1.txt'
with open(path) as f:
    text=f.read()
words = text.split()
wc={}
for word in words:
    wc[word]=wc.get(word,0)+1
wclist=list(wc.items())
wclist.sort(key=lambda x:x[1],reverse=True)
print(wclist)

3. 运行及运行结果

image

其他,非必要

1. 更改apt更新源,加快软件安装速度。

image

2. 安装zsh, ohmyzsh。更好的终端体验。

参考链接
image

posted @ 2022-03-02 18:53  紫陌凛风  阅读(38)  评论(0编辑  收藏  举报