Install Homebrew(Package manager):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew upgrade && brew update
If not installed, install:
- Java:
- Check:
java -version
echo 'export PATH="/opt/homebrew/opt/openjdk/bin:$PATH"' >> ~/.zshrc
- Install:.
brew install java
- Check:
- Python:
- Check:
python3 --version
- Install:
$(brew --prefix python)/libexec/bin
- Check:
- Scala:
- Check:
scala -help
- Install:
brew install scala
- Check:
- Apache spark:
- Check:
spark-shell
- Install:
brew install apache-spark
- Set
SPARK_HOME
environment variable:echo 'export SPARK_HOME="/opt/homebrew/Cellar/apache-spark/3.5.0/libexec/"' >> ~/.zshrc
source ~/.zshrc
- Check:
Python setup:
- Create virtual environment:
python3 -m venv $PWD
- Activate virtual environment:
source ./bin/activate
- Install packages:
pip3 install notebook
pip3 install findspark
- Start jupyter notebook:
jupyter notebook
- Test in jupyter:
import findspark
findspark.init()
import pyspark # only run after findspark.init()
from pyspark.sql import SparkSession
spark = SparkSession.builder.getOrCreate()
df = spark.sql('''select 'spark' as hello ''')
df.show()
- When done, deactivate virtual environment:
deactivate
Note: Use pip3
and python3
instead of pip
and python
References:
- How to Install Scala and Apache Spark on MacOS | by Jose Marcial Portilla | We’ve moved to freeCodeCamp.org/news | Medium
- Installing Apache Spark on Mac OS | by Diwakar | Beer&Diapers.ai | Medium
- How to activate Python venv on a Mac? | by Manzeel Uprety | Medium
- macos - How to find installation directory of Apache Spark package in Homebrew? - Stack Overflow