You are currently viewing Install Pyspark 3.5 using pip or conda

There are multiple ways to install PySpark depending on your environment and use case. You can install just a PySpark package and connect to an existing cluster or Install complete Apache Spark (includes PySpark package) to setup your own cluster.

Advertisements

In this article, I will cover step-by-step installing pyspark by using pip, Anaconda(conda command), manually on Windows and Mac.

Ways to Install

  1. Manually download and install by yourself.
  2. Use Python PIP to setup PySpark and connect to an existing cluster.
  3. Use Anaconda to setup PySpark with all it’s features.

1. Install Python

Regardless of which process you use you need to install Python to run PySpark. If you already have Python skip this step. Check if you have Python by using python --version or python3 --version from the command line.

On Windows – Download Python from Python.org and install it.

On Mac – Install python using the below command. If you don’t have a brew, install it first by following https://brew.sh/.


# install Python
brew install python

2. Install Java

PySpark required Java to run.

On Windows – Download OpenJDK from adoptopenjdk and install it.

On Mac – Run the below command on the terminal to install Java.


# install Java
brew install openjdk@11

3. PySpark Install Using pip

You can install just a PySpark package by using the pip python installer.

Note that using Python pip you can install only the PySpark package which is used to test your jobs locally or run your jobs on an existing cluster running with Yarn, Standalone, or Mesos. It does not contain features/libraries to set up your own cluster. If you want PySpark with all its features including starting your own cluster then install it from Anaconda or by using the above approach.

Install pip on Mac & Windows – Follow the instructions from the below link to install pip.


#Install pip
https://pip.pypa.io/en/stable/installing/

For Python users, PySpark provides pip installation from PyPI. Python pip is a package manager that is used to install and uninstall third-party packages that are not part of the Python standard library. Using pip you can install/uninstall/upgrade/downgrade any python library that is part of the Python Package Index.

If you already have pip installed, upgrade pip to the latest version before installing PySpark.


# Install pyspark from pip
pip install pyspark

This pip command starts collecting the PySpark package and installing it. You should see something like this below on the console if you are using Mac.

pyspark install pip

As I said earlier this does not contain all features of Apache Spark hence you can not setup your own cluster but use this to connect to the existing cluster to run jobs and run jobs locally.

3.3 Using Anaconda

Follow Install PySpark using Anaconda & run Jupyter notebook

4. Test PySpark Install from Shell

Regardless of which method you have used, once successfully install PySpark, launch pyspark shell by entering pyspark from the command line. PySpark shell is a REPL that is used to test and learn pyspark statements.

pyspark install pip

To submit a job on the cluster, use a spark-submit command that comes with install.

If you encounter any issues setting up PySpark on Mac and Windows following the above steps, please comment. I will be happy to help you and correct the steps.

Happy Learning !!