← Back to writing

March 04, 2024 · 1 min read

Engineering

PySpark initialization outside the Pyspark shell

PySpark with findspark: SparkSession without the pyspark shell.

How you do it with the findspark package without the need to startup a Spark shell with the options to load within a jupyterlab session.

try:
    import findspark
    findspark.init()
except ImportError:
    pass

from pyspark import SparkConf, SparkContext
from pyspark.sql import SparkSession
import os

spark = (
    SparkSession
    .builder
    .master("local[*]")
    .appName("exercises_notebook")
    .config("spark.sql.catalogImplementation","in-memory")
    .config("spark.sql.warehouse.dir", os.getcwd())
    .getOrCreate()
)

Continue exploring

All articles ↗