12 Installing and Using VS Code
12.1 Introduction
In this lesson, we will explore Visual Studio Code (VS Code), a powerful and versatile editor for writing, running, and debugging Python code. VS Code is widely used due to its rich feature set and extensive extension library, which makes coding more efficient and enjoyable.
Note that this lesson is better consumed as a video, since there are many Graphic-user-interface steps that are hard to describe in writing.
12.2 Learning Objectives
By the end of this lesson, you should be able to:
- Open VS Code and navigate to the editor, terminal, and explorer tabs.
- Create a new Python file and run it using the Python extension.
- Use the Command Palette to search for and select a color theme.
12.3 Installing VS Code
VS Code is available for Windows, macOS, and Linux. Search for “VS Code” in your favorite search engine and go to the official website, code.visualstudio.com. Download the version for your computer’s operating system.
For macOs users, after installing VS Code, you may need to drag the icon to your applications folder.
From your applications folder, open VS Code.
12.5 Writing and Saving Python Code
Let’s write some Python code in your new file:
print(2 + 2)
To save the file, press Ctrl + S
(or Cmd + S
on macOS).
12.6 Installing the Python Extension
To run Python code within VS Code, we need to install the Python extension:
- Click on the Extensions tab on the left sidebar (it looks like four squares).
- In the search bar at the top, type “Python”.
- Find the extension named “Python” published by Microsoft, and click Install.
12.7 Running Your Python Script
With the Python extension installed, you can now run your script:
Open
first_script.py
if it’s not already open.Click on the Run icon (a play button) in the top right corner of the editor.
- Alternatively, you can right-click inside the editor and select RUn python then “Run Python File in Terminal”.
A terminal window will open at the bottom of the screen, and your code will execute. You should see the output:
4
12.8 Using the Command Palette
The Command Palette is a powerful feature in VS Code that allows you to access various commands and settings:
To access it, click on the search bar at the top of vscode window, then either press > or select the ‘show and run commands’ option.
Let’s practice changing the color theme:
Type ‘theme’ and select ‘Preferences: Color Theme’.
Use the up and down arrow keys to cycle through the available color themes.
Press
Enter
to select your preferred theme.
12.9 Wrap Up
In this lesson, we’ve:
- Installed VS Code and set up a workspace.
- Created and saved a Python script.
- Installed the Python extension to enable running and debugging code.
- Used the Command Palette to customize the editor’s appearance.
Happy coding!