After reading this, you will be able to execute python files and jupyter notebooks that execute Apache Spark code in your local environment. This tutorial applies to OS X and Linux systems. We assume you already have knowledge on python and a console environment.
- Python is an interpreted language, and in order to run Python code and get Python IntelliSense, you must tell VS Code which interpreter to use. From within VS Code, select a Python 3 interpreter by opening the Command Palette (Ctrl+Shift+P), start typing the Python: Select Interpreter command to search, then select the command.
- Visual Studio Code vs. Visual Studio: How to choose Deciding between Visual Studio Code and Visual Studio may depend as much on your work style as on the language support and features you need.
- Python is not presently supported in Visual Studio for Mac, but is available on Mac and Linux through Visual Studio Code (see questions and answers).
1. Download Apache Spark
We will download the latest version currently available at the time of writing this: 3.0.1 from the official website.
![Python Mac Visual Studio Code Python Mac Visual Studio Code](/uploads/1/1/8/5/118550621/652959066.png)
Developer community 2. Search Search Microsoft.com.
Google earth for mac os mojave. Download it and extract it in your computer. The path I'll be using for this tutorial is
/Users/myuser/bigdata/spark
This folder will contain all the files, like thisNow, I will edit the
.bashrc
file, located in the home of your user![Desktop](/uploads/1/1/8/5/118550621/558326570.png)
Then we will update our environment variables so we can execute spark programs and our python environments will be able to locate the spark libraries.
Mac Visual Studio Code Python
Save the file and load the changes executing
$ source ~/.bashrc
. If this worked, you will be able to open an spark shell.![Python Mac Visual Studio Code Python Mac Visual Studio Code](/uploads/1/1/8/5/118550621/536574983.gif)
We are now done installing Spark.
2. Install Visual Studio Code
Visual Studio Code Python On Mac
One of the good things of this IDE is that allows us to run Jupyter notebooks within itself. Follow the Set-up instructions and then install python and the VSCode Python extension.
Then, open a new terminal and install the pyspark package via pip
$ pip install pyspark
. Note: depending on your installation, the command changes to pip3
.3. Run your pyspark code
Create a new file or notebook in VS Code and you should be able to execute and get some results using the Pi example provided by the library itself.
Troubleshoot
If you are in a distribution that by default installs python3 (e.g. Ubuntu 20.04), pyspark will mostly fail with a message error like
pysparkenv: 'python': No such file or directory
.Python Tool For Visual Studio
The first option to fix it is to add to your
.profile
or .bashrc
files the following contentRemember to always reload the configuration via
source .bashrc
In this case, the solution worked if I executed pyspark from the command line but not from VSCode's notebook. Since I am using a distribution based on debian, installing tehe following package fixed it:
Visual Studio Python Examples
sudo apt-get install python-is-python3