Whether it’s for social science, marketing, business intelligence or something else, the number of times data analysis benefits from heavy duty parallelization is growing all the time.
Spark is an Open Source, cross-platform IM client optimized for businesses and organizations. It features built-in support for group chat, telephony integration, and strong security.
- You can download the full version of Spark from the Apache Spark downloads page. NOTE: If you are using this with a Spark standalone cluster you must ensure that the version (including minor version) matches or you may experience odd errors.
- Installing Pyspark. I recommend that you install Pyspark in your own virtual environment using pipenv to keep things clean and separated. Make yourself a new folder somewhere, like /coding/pyspark-project and move into it $ cd /coding/pyspark-project. Create a new environment $ pipenv -three if you want to use Python 3.
Apache Spark is an awesome platform for big data analysis, so getting to know how it works and how to use it is probably a good idea. Setting up your own cluster, administering it etc. etc. is a bit of a hassle to just learn the basics though (although Amazon EMR or Databricks make that quite easy, and you can even build your own Raspberry Pi cluster if you want…), so getting Spark and Pyspark running on your local machine seems like a better idea. You can also use Spark with R and Scala, among others, but I have no experience with how to set that up. So, we’ll stick to Pyspark in this guide.
While dipping my toes into the water I noticed that all the guides I could find online weren’t entirely transparent, so I’ve tried to compile the steps I actually did to get this up and running here. The original guides I’m working from are here, here and here.
Pre-requesites
Before we can actually install Spark and Pyspark, there are a few things that need to be present on your machine.
You need:
- The XCode Developer Tools
homebrewpipenv- Java (v8)
Installing the XCode Developer Tools
- Open Terminal
- Type
xcode-select --install - Confirm, proceed with install

Installing homebrew
- Open Terminal
- Paste the command listed on the brew homepage: brew.sh
At the time of this writing, that’s/usr/bin/ruby -e '$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)'
Installing Pipenv

- Open Terminal
- Type
brew install pipenv
If that doesn’t work for some reason, you can do the following:

- Open Terminal
- Type
pip install --user pipenv
This does a pip user install, which puts pipenv in your home directory. If pipenv isn’t available in your shell after installation, you need to add stuff to you PATH. Here’s pipenv’s guide on how to do that.
Installing Java
To run, Spark needs Java installed on your system. It’s important that you do not install Java with brew for uninteresting reasons.
Just go here to download Java for your Mac and follow the instructions.
You can confirm Java is installed by typing $ java --showversion in Terminal.
Installing Spark
With the pre-requisites in place, you can now install Apache Spark on your Mac.
Go to the Apache Spark Download Page
Download the newest version, a file ending in
.tgzUnzip this file in Terminal
$ tar -xzf spark-2.4.3-bin-hadoop2.7.tgzMove the file to your
/optfolder$ sudo mv spark-2.4.3-bin-hadoop2.7 /opt/spark-2.4.3Create a symbolic link (symlink) to your Spark version
$ sudo ln -s /opt/spark-2.4.3 /opt/spark
What’s happening here? By creating a symbolic link to our specific version (2.4.3) we can have multiple versions installed in parallel and only need to adjust the symlink to work with them.Tell your shell where to find Spark
Until macOS 10.14 the default shell used in the Terminal app wasbash, but from 10.15 on it is Zshell (zsh). So depending on your version of macOS, you need to do one of the following:$ nano ~/.bashrc(10.14)$ nano ~/.zshrc(10.15)
Set Spark variables in your
~/.bashrc/~/.zshrcfile
Installing Pyspark
I recommend that you install Pyspark in your own virtual environment using pipenv to keep things clean and separated.
Open Terminal
Make yourself a new folder somewhere, like
~/coding/pyspark-projectand move into it$ cd ~/coding/pyspark-projectCreate a new environment
$ pipenv --threeif you want to use Python 3$ pipenv --twoif you want to use Python 2
Install pyspark
$ pipenv install pysparkInstall Jupyter
$ pipenv install jupyterNow tell Pyspark to use Jupyter: in your
~/.bashrc/~/.zshrcfile, addIf you want to use Python 3 with Pyspark (see step 3 above), you also need to add:
Your ~/.bashrc or ~/.zshrc should now have a section that looks kinda like this:
Now you save the file, and source your Terminal:
$ source ~/.bashrcor$ source ~/.zshrc
To start Pyspark and open up Jupyter, you can simply run $ pyspark. You only need to make sure you’re inside your pipenv environment. That means:
- Go to your pyspark folder (
$ cd ~/coding/pyspark project) - Type
$ pipenv shell - Type
$ pyspark
Using Pyspark inside your Jupyter Notebooks
To test whether Pyspark is running as it is supposed to, put the following code into a new notebook and run it:
(You might need to install numpy inside your pipenv environment if you haven’t already done so without my instruction 😉)
If you get an error along the lines of sc is not defined, you need to add sc = SparkContext.getOrCreate() at the top of the cell. If things are still not working, make sure you followed the installation instructions closely.
Still no luck? Send me an email if you want (I most definitely can’t guarantee that I know how to fix your problem), particularly if you find a bug and figure out how to make it work!
Related
Here is an easy Step by Step guide to installing PySpark and Apache Spark on MacOS.
Step 1: Get Homebrew
Homebrew makes installing applications and languages on a Mac OS a lot easier. You can get Homebrew by following the instructions on its website.
In short you can install Homebrew in the terminal using this command:
Step 2: Installing xcode-select
Xcode is a large suite of software development tools and libraries from Apple. In order to install Java, and Spark through the command line we will probably need to install xcode-select.
Use the blow command in your terminal to install Xcode-select: xcode-select –install
You usually get a prompt that looks something like this to go further with installation:
You need to click “install” to go further with the installation.
Step 3: DO NOT use Homebrew to install Java!
The latest version of Java (at time of writing this article), is Java 10. And Apache spark has not officially supported Java 10! Homebrew will install the latest version of Java and that imposes many issues!
To install Java 8, please go to the official website: https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Then From “Java SE Development Kit 8u191” Choose:
Pyspark Download Mac Iso
Mac OS X x64 245.92 MB jdk-8u191-macosx-x64.dmg
To download Java. Once Java is downloaded please go ahead and install it locally.
Step 3: Use Homebrew to install Apache Spark
To do so, please go to your terminal and type: brew install apache-spark Homebrew will now download and install Apache Spark, it may take some time depending on your internet connection. You can check the version of spark using the below command in your terminal: pyspark –version
You should then see some stuff like below:
Step 4: Install PySpark and FindSpark in Python
Pyspark Download Mac Free
To be able to use PyPark locally on your machine you need to install findspark and pyspark
If you use anaconda use the below commands:
Step 5: Your first code in Python
After the installation is completed you can write your first helloworld script:

Install Pyspark Pip
