This worked for me:

import os
import sys

spark_path = "D:\spark"

os.environ['SPARK_HOME'] = spark_path
os.environ['HADOOP_HOME'] = spark_path

sys.path.append(spark_path + "/bin")
sys.path.append(spark_path + "/python")
sys.path.append(spark_path + "/python/pyspark/")
sys.path.append(spark_path + "/python/lib")
sys.path.append(spark_path + "/python/lib/pyspark.zip")
sys.path.append(spark_path + "/python/lib/py4j-0.9-src.zip")

from pyspark import SparkContext
from pyspark import SparkConf

sc = SparkContext("local", "test")

To verify:

In [2]: sc
Out[2]: <pyspark.context.SparkContext at 0x707ccf8>
Answer from James Ma on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-install-pyspark-in-jupyter-notebook
How to Install PySpark in Jupyter Notebook - GeeksforGeeks
July 23, 2025 - If it's not already, install Jupyter Notebook using pip: ... # Import PySpark and initialize Spark session import pyspark from pyspark.sql import SparkSession # Create a Spark session spark = SparkSession.builder.appName("PySparkExample").g...
🌐
Spark By {Examples}
sparkbyexamples.com › home › pyspark › install pyspark in anaconda & jupyter notebook
Install PySpark in Anaconda & Jupyter Notebook - Spark By {Examples}
July 30, 2025 - Step 5. Validate PySpark Installation from pyspark shell · Step 6. PySpark in Jupyter notebook · Step 7. Run PySpark from IDE ... From https://anaconda.com/ download the Anaconda Individual Edition, for windows you download the .exe file, and for Mac, download the .pkg file.
Top answer
1 of 3
8

This worked for me:

import os
import sys

spark_path = "D:\spark"

os.environ['SPARK_HOME'] = spark_path
os.environ['HADOOP_HOME'] = spark_path

sys.path.append(spark_path + "/bin")
sys.path.append(spark_path + "/python")
sys.path.append(spark_path + "/python/pyspark/")
sys.path.append(spark_path + "/python/lib")
sys.path.append(spark_path + "/python/lib/pyspark.zip")
sys.path.append(spark_path + "/python/lib/py4j-0.9-src.zip")

from pyspark import SparkContext
from pyspark import SparkConf

sc = SparkContext("local", "test")

To verify:

In [2]: sc
Out[2]: <pyspark.context.SparkContext at 0x707ccf8>
2 of 3
2

2018 version

INSTALL PYSPARK on Windows 10 JUPYTER-NOTEBOOK With ANACONDA NAVIGATOR

STEP 1

Download Packages

1) spark-2.2.0-bin-hadoop2.7.tgz Download

2) java jdk 8 version Download

3) Anaconda v 5.2 Download

4) scala-2.12.6.msi Download

5) hadoop v2.7.1Download

STEP 2

MAKE SPARK FOLDER IN C:/ DRIVE AND PUT EVERYTHING INSIDE IT It will look like this

NOTE : DURING INSTALLATION OF SCALA GIVE PATH OF SCALA INSIDE SPARK FOLDER

STEP 3

NOW SET NEW WINDOWS ENVIRONMENT VARIABLES

  1. HADOOP_HOME=C:\spark\hadoop

  2. JAVA_HOME=C:\Program Files\Java\jdk1.8.0_151

  3. SCALA_HOME=C:\spark\scala\bin

  4. SPARK_HOME=C:\spark\spark\bin

  5. PYSPARK_PYTHON=C:\Users\user\Anaconda3\python.exe

  6. PYSPARK_DRIVER_PYTHON=C:\Users\user\Anaconda3\Scripts\jupyter.exe

  7. PYSPARK_DRIVER_PYTHON_OPTS=notebook

  8. NOW SELECT PATH OF SPARK :

    Click on Edit and add New

    Add "C:\spark\spark\bin” to variable “Path” Windows

STEP 4

  • Make folder where you want to store Jupyter-Notebook outputs and files
  • After that open Anaconda command prompt and cd Folder name
  • then enter Pyspark

thats it your browser will pop up with Juypter localhost

STEP 5

Check pyspark is working or not !

Type simple code and run it

from pyspark.sql import Row
a = Row(name = 'Vinay' , age=22 , height=165)
print("a: ",a)
🌐
PhoenixNAP
phoenixnap.com › home › kb › devops and development › how to run pyspark on jupyter notebook
How to Run PySpark on Jupyter Notebook | phoenixNAP KB
June 25, 2025 - This guide shows two ways to run PySpark on a Jupyter Notebook. Follow these simple step-by-step installation and setup instructions.
🌐
Medium
medium.com › @uzzaman.ahmed › setup-pyspark-on-local-machine-and-link-it-with-jupyter-notebook-windows-e08349e792db
Setup PySpark on Local Machine and link it with Jupyter Notebook — Windows | by Ahmed Uz Zaman | Medium
January 6, 2023 - This Article has step-by-step instructions on how to setup Apache Spark (PySpark) and Jupyter Notebook on your local Windows machine. ... Follow the installation prompts to complete the setup.
🌐
Chang Hsin Lee
changhsinlee.com › install-pyspark-windows-jupyter
How to Install and Run PySpark in Jupyter Notebook on Windows
December 30, 2017 - Python and Jupyter Notebook. You can get both by installing the Python 3.x version of Anaconda distribution. winutils.exe — a Hadoop binary for Windows — from Steve Loughran’s GitHub repo. Go to the corresponding Hadoop version in the Spark distribution and find winutils.exe under /bin.
🌐
YouTube
youtube.com › eden canlilar
How to Install and Run PySpark in Jupyter Notebook on Windows - YouTube
Hello world! Hello World! Some of my students have been having a hard time with a couple of the steps involved with setting up PySpark from Chang Hsin Lee's ...
Published   November 21, 2020
Views   41K
🌐
Opensource.com
opensource.com › article › 18 › 11 › pyspark-jupyter-notebook
How to set up PySpark for your Jupyter notebook | Opensource.com
November 12, 2018 - Install Apache Spark; go to the Spark download page and choose the latest (default) version. I am using Spark 2.3.1 with Hadoop 2.7. After downloading, unpack it in the location you want to use it.
Find elsewhere
🌐
YouTube
youtube.com › learn by doing it
Install spark and PySpark on Windows | Spark Installation Guide - YouTube
#pyspark #spark #dataengineer #azuredataengineer How to install spark and PySpark on Windowsuse pyspark in jupyter notebookwe're going to setup Apache Spark ...
Published   October 16, 2023
Views   4K
🌐
YouTube
youtube.com › michael galarnyk
Install Spark on Windows (PySpark) + Configure Jupyter Notebook - YouTube
Step by Step Guide: https://medium.com/@GalarnykMichael/install-spark-on-windows-pyspark-4498a5d8d66c Estimating Pi: https://github.com/mGalarnyk/Installatio...
Published   April 2, 2017
Views   84K
🌐
YouTube
youtube.com › the code city
How to Install PySpark in Jupyter Notebook (2023) - YouTube
In this video, I'll show you how you can Install PySpark in Jupyter Notebook.By Installing PySpart in Jupyter Notebook. You can easily process large data pro...
Published   October 9, 2023
Views   19K
🌐
Medium
medium.com › @marcelopedronidasilva › how-to-install-and-run-pyspark-locally-integrated-with-vscode-via-jupyter-notebook-on-windows-ff209ac8621f
How to install and run Pyspark locally integrated with VSCode via Jupyter Notebook (on Windows). | by Marcelo Pedroni da Silva | Medium
July 18, 2024 - How to install and run Pyspark locally integrated with VSCode via Jupyter Notebook (on Windows). If you ever wonder, how can I pratice or just do some coding using PySpark on windows, besides using …
🌐
Microsoft Learn
learn.microsoft.com › en-us › azure › hdinsight › spark › apache-spark-jupyter-notebook-install-locally
Install Jupyter locally and connect to Spark in Azure HDInsight | Microsoft Learn
In this article, you learn how to install Jupyter Notebook with the custom PySpark (for Python) and Apache Spark (for Scala) kernels with Spark magic.
Top answer
1 of 5
7

I'm assuming you already have spark and jupyter notebooks installed and they work flawlessly independent of each other.

If that is the case, then follow the steps below and you should be able to fire up a jupyter notebook with a (py)spark backend.

  1. Go to your spark installation folder and there should be a bin directory there: /path/to/spark/bin

  2. Create a file, let's call it start_pyspark.sh

  3. Open start_pyspark.sh and write something like:

        #!/bin/bash
    
    
    export PYSPARK_PYTHON=/path/to/anaconda3/bin/python
    export PYSPARK_DRIVER_PYTHON=/path/to/anaconda3/bin/jupyter
    export PYSPARK_DRIVER_PYTHON_OPTS="notebook --NotebookApp.open_browser=False --NotebookApp.ip='*' --NotebookApp.port=8880"
    
    pyspark "$@"
    

Replace the /path/to ... with the path where you have installed your python and jupyter binaries respectively.

  1. Most probably this step is already done, but just in case
    Modify your ~/.bashrc file by adding the following lines

        # Spark
        export PATH="/path/to/spark/bin:/path/to/spark/sbin:$PATH"
        export SPARK_HOME="/path/to/spark"
        export SPARK_CONF_DIR="/path/to/spark/conf"
    

Run source ~/.bashrc and you are set.

Go ahead and try start_pyspark.sh.
You could also give arguments to the script, something like start_pyspark.sh --packages dibbhatt:kafka-spark-consumer:1.0.14.

Hope it works out for you.

2 of 5
6

Assuming you have Spark installed wherever you are going to run Jupyter, I'd recommend you use findspark. Once you pip install findspark, you can just

import findspark
findspark.init()

import pyspark
sc = pyspark.SparkContext(appName="myAppName")

... and go

🌐
LinkedIn
linkedin.com › pulse › step-by-step-guide-install-pyspark-windows-pc-2024-manav-nayak-wmpbf
Step-by-Step Guide to Install PySpark on Windows PC | 2024
August 8, 2024 - pip install ipykernel pyspark pandas pyarrow · Open a new Python or Jupyter notebook file in the visual studio code (Navigate to File --> New File) and run the following code.
🌐
BMC Software
bmc.com › blogs › jupyter-notebooks-apache-spark
How to Use Jupyter Notebooks With Apache Spark – BMC Software | Blogs
November 8, 2024 - However, you also have the option of installing PySpark and the extra dependencies like Spark SQL or Pandas for Spark as a separate installation via the Python package manager. You can directly launch PySpark by running the following command in the terminal. ... The only requirement to get the Jupyter Notebook reference PySpark is to add the following environmental variables in your .bashrc or .zshrc file, which points PySpark to Jupyter.
🌐
LinkedIn
linkedin.com › pulse › how-use-pyspark-jupyter-notebook-codersarts
How to use pyspark in jupyter Notebook
November 17, 2022 - After that, create a new jupyter notebook script by clicking on the new button which appears in the right corner on top and then select python3. Now we can perform the pyspark operation in the notebook.
🌐
LinkedIn
linkedin.com › pulse › import-pyspark-jupyter-notebook-windows-krishna-jadhav
Import Pyspark in Jupyter notebook on Windows
January 31, 2022 - ... import pyspark from pyspark.sql import SparkSession spark = SparkSession.builder.getOrCreate() df = spark.sql("select 'spark' as hello ") df.show() If you are getting the hello spark as a output means you are successfully installed Pyspark .
🌐
GitHub
gist.github.com › clayms › d442a08f4d7177e056a6d208d4c3cf52
Get pySpark to work in Jupyter notebooks on Windows 10. · GitHub
FOR /F "delims=~" %f in (requirements.txt) DO conda install --yes "%f" || pip install "%f" If you want to run pyspark in a jupyter notebook, you will also have to install jupyter in this new python environment.