Visual Studio Code Python Mac



In this Python Programming Tutorial, we will be learning how to set up a Python development environment in VSCode on MacOS. VSCode is a very nice free editor for writing Python applications and many developers are now switching over to this editor. In this video, we will learn how to install VSCode, get the Python extension installed, how to change Python interpreters, create virtual environments, format/lint our code, how to use Git within VSCode, how to debug our programs, how unit testing works, and more. We have a lot to cover, so let’s go ahead and get started…

VSCode on Windows – https://youtu.be/-nh9rCzPJ20

Download Python Visual Studio Code

Installing and Configuring Visual Studio Code for Python Development. Installing Visual Studio Code is very accessible on any platform. Full instructions for Windows, Mac, and Linux are available, and the editor is updated monthly with new features and bug fixes. Visual Studio Code is free and available on your favorite platform - Linux, macOS, and Windows. Download Visual Studio Code to experience a redefined code editor, optimized for building and debugging modern web and cloud applications.

Timestamps for topics in this tutorial:
Installation – 1:11
Python Extension – 6:21
Switching Interpreters – 10:16
Changing Color Themes – 13:08
VSCode Settings – 17:12
Set Default Python – 22:24
Using Virtual Environments – 25:52
IntelliSense – 30:28
Code Formatting – 33:08
Code Linting – 38:01
Code Runner Extension – 40:45
Git Integration – 49:05
Debugging – 58:15
Unit Testing – 1:02:38
Zen Mode – 1:10:42

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.

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.

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 this

Now, I will edit the .bashrc file, located in the home of your user

Code

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.

Save the file and load the changes executing $ source ~/.bashrc. If this worked, you will be able to open an spark shell.

Visual Studio Code Python Machine Learning

We are now done installing Spark.

2. Install Visual Studio Code

Anydesk 5.4.2. 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.

Visual studio code python 设定 mac

The first option to fix it is to add to your .profile or .bashrc files the following content

Visual Studio Code Python Virtualenv Mac

Remember 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 Code Python Mac

sudo apt-get install python-is-python3