Here is an easy Step by Step guide to installing PySpark and Apache Spark on MacOS.
- Pyspark Download Mac Installer
- Pyspark Download Mac Free
- Pyspark Download Mac
- Pyspark Download Windows 10
- Pyspark Download Mac Tutorial
Conda install linux-64 v2.4.0; win-32 v2.3.0; noarch v3.0.1; osx-64 v2.4.0; win-64 v2.4.0; To install this package with conda run one of the following: conda install -c conda-forge pyspark. Choose a download type: Direct download. Click on the link next to Download Spark: It should state something similar to spark-2.1.0.tgz. Once the download finishes, go to your CLI and navigate to the folder you have downloaded the file to; /Downloads/in our case it is: cd /Downloads.
Apache Spark is one of the hottest and largest open source project in data processing framework with rich high-level APIs for the programming languages like Scala, Python, Java and R. It realizes the potential of bringing together both Big Data and machine learning. I have used Spark in Scala for a long time. Now I am using pyspark for the first time. This is on a Mac. First I installed pyspark using conda install pyspark, and it installed pyspark 2.2.0; I installed spark itself using brew install apache-spark, and it seems to have installed apache-spark 2.2.0; but when I run pyspark, it dumps out.
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:
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:
Pyspark Download Mac Installer
Step 4: Install PySpark and FindSpark in Python
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:
I decided to teach myself how to work with big data and came across Apache Spark. While I had heard of Apache Hadoop, to use Hadoop for working with big data, I had to write code in Java which I was not really looking forward to as I love to write code in Python. Spark supports a Python programming API called PySpark that is actively maintained and was enough to convince me to start learning PySpark for working with big data.
In this post, I describe how I got started with PySpark on Windows. My laptop is running Windows 10. So the screenshots are specific to Windows 10. I am also assuming that you are comfortable working with the Command Prompt on Windows. You do not have to be an expert, but you need to know how to start a Command Prompt and run commands such as those that help you move around your computer’s file system. In case you need a refresher, a quick introduction might be handy.
Often times, many open source projects do not have good Windows support. So I had to first figure out if Spark and PySpark would work well on Windows. The official Spark documentation does mention about supporting Windows.
Installing Prerequisites
PySpark requires Java version 7 or later and Python version 2.6 or later. Let’s first check if they are already installed or install them and make sure that PySpark can work with these two components.
Java
Java is used by many other software. So it is quite possible that a required version (in our case version 7 or later) is already available on your computer. To check if Java is available and find it’s version, open a Command Prompt and type the following command.
If Java is installed and configured to work from a Command Prompt, running the above command should print the information about the Java version to the console. For example, I got the following output on my laptop.
Instead if you get a message like
It means you need to install Java. To do so,
Go to the Java download page. In case the download link has changed, search for
Java SE Runtime Environment
on the internet and you should be able to find the download page.Click the Download button beneath JRE
Accept the license agreement and download the latest version of
Java SE Runtime Environment
installer. I suggest getting the exe for Windows x64 (such asjre-8u92-windows-x64.exe
) unless you are using a 32 bit version of Windows in which case you need to get the Windows x86 Offline version.Run the installer.
After the installation is complete, close the Command Prompt if it was already open, open it and check if you can successfully run java -version
command.
Python
Python is used by many other software. So it is quite possible that a required version (in our case version 2.6 or later) is already available on your computer. To check if Python is available and find it’s version, open a Command Prompt and type the following command.
If Python is installed and configured to work from a Command Prompt, running the above command should print the information about the Python version to the console. For example, I got the following output on my laptop.
Instead if you get a message like
It means you need to install Python. To do so,
Go to the Python download page.
Click the Latest Python 2 Release link.
Download the
Windows x86-64 MSI installer
file. If you are using a 32 bit version of Windows download theWindows x86 MSI installer
file.When you run the installer, on the Customize Python section, make sure that the option Add python.exe to Path is selected. If this option is not selected, some of the PySpark utilities such as
pyspark
andspark-submit
might not work.
After the installation is complete, close the Command Prompt if it was already open, open it and check if you can successfully run python --version
command.
Installing Apache Spark
Go to the Spark download page.
For Choose a Spark release, select the latest stable release of Spark.
For Choose a package type, select a version that is pre-built for the latest version of Hadoop such as Pre-built for Hadoop 2.6.
For Choose a download type, select Direct Download.
Click the link next to Download Spark to download a zipped tarball file ending in .tgz extension such as
spark-1.6.2-bin-hadoop2.6.tgz
.In order to install Apache Spark, there is no need to run any installer. You can extract the files from the downloaded tarball in any folder of your choice using the 7Zip tool.
Make sure that the folder path and the folder name containing Spark files do not contain any spaces.
In my case, I created a folder called spark
on my C drive and extracted the zipped tarball in a folder called spark-1.6.2-bin-hadoop2.6
. So all Spark files are in a folder called C:sparkspark-1.6.2-bin-hadoop2.6
. From now on, I will refer to this folder as SPARK_HOME
in this post.
To test if your installation was successful, open a Command Prompt, change to SPARK_HOME directory and type binpyspark
. This should start the PySpark shell which can be used to interactively work with Spark. I got the following messages in the console after running binpyspark
command.
The last message provides a hint on how to work with Spark in the PySpark shell using the sc
or sqlContext
names. For example, typing sc.version
in the shell should print the version of Spark. You can exit from the PySpark shell in the same way you exit from any Python shell by typing exit()
.
The PySpark shell outputs a few messages on exit. So you need to hit enter to get back to the Command Prompt.
Configuring the Spark Installation
Starting the PySpark shell produces a lot of messages of type INFO, ERROR and WARN. In this section we will see how to remove these messages.
By default, the Spark installation on Windows does not include the winutils.exe
utility that is used by Spark. If you do not tell your Spark installation where to look for winutils.exe
, you will see error messages when running the PySpark shell such as
This error message does not prevent the PySpark shell from starting. However if you try to run a standalone Python script using the binspark-submit
utility, you will get an error. For example, try running the wordcount.py
script from the examples
folder in the Command Prompt when you are in the SPARK_HOME directory.
Pyspark Download Mac Free
which produces the following error that also points to missing winutils.exe
Installing winutils
Let’s download the winutils.exe
and configure our Spark installation to find winutils.exe
.
Create a
hadoopbin
folder inside the SPARK_HOME folder.Download the winutils.exe for the version of hadoop against which your Spark installation was built for. In my case the hadoop version was 2.6.0. So I downloaded the winutils.exe for hadoop 2.6.0 and copied it to the
hadoopbin
folder in the SPARK_HOME folder.Create a system environment variable in Windows called
SPARK_HOME
that points to the SPARK_HOME folder path. Search the internet in case you need a refresher on how to create environment variables in your version of Windows such as articles like these.Create another system environment variable in Windows called
HADOOP_HOME
that points to the hadoop folder inside the SPARK_HOME folder.
Since the hadoop
folder is inside the SPARK_HOME folder, it is better to create HADOOP_HOME
environment variable using a value of %SPARK_HOME%hadoop
. That way you don’t have to change HADOOP_HOME
if SPARK_HOME
is updated.
If you now run the binpyspark
script from a Windows Command Prompt, the error messages related to winutils.exe
should be gone. For example, I got the following messages after running the binpyspark
utility after configuring winutils
The binspark-submit
utility can also be successfully used to run wordcount.py
script.
Configuring the log level for Spark
There are still a lot of extra INFO messages in the console everytime you start or exit from a PySpark shell or run the spark-submit
utility. So let’s make one more change to our Spark installation so that only warning and error messages are written to the console. In order to do this
Copy the
log4j.properties.template
file in theSPARK_HOMEconf
folder aslog4j.properties
file in theSPARK_HOMEconf
folder.Set the
log4j.rootCategory
property value toWARN, console
Save the
log4j.properties
file.
Now any informative messages will not be logged to the console. For example, I got the following messages after running the binpyspark
utility once I configured the log level to WARN.
Summary
In order to work with PySpark, start a Windows Command Prompt and change into your SPARK_HOME directory.
To start a PySpark shell, run the
binpyspark
utility. Once your are in the PySpark shell use thesc
andsqlContext
names and typeexit()
to return back to the Command Prompt.To run a standalone Python script, run the
binspark-submit
utility and specify the path of your Python script as well as any arguments your Python script needs in the Command Prompt. For example, to run thewordcount.py
script fromexamples
directory in your SPARK_HOME folder, you can run the following commandbinspark-submit examplessrcmainpythonwordcount.py README.md
Pyspark Download Mac
References
I used the following references to gather information about this post.
Downloading Spark and Getting Started (chapter 2) from O’Reilly’s Learning Spark book.
Pyspark Download Windows 10
Share on: Twitter ❄ Facebook ❄ Google+ ❄ Email
Any suggestions or feedback? Leave your comments below.