CHAPTER 2Hello World for Python

As mentioned in Chapter 1, “Getting Started,” support for most languages in Visual Studio Code, including Python, comes through means of extensions. To use Python, then, you must install the extension along with a suitable Python interpreter. Creating and running your first Hello World Python file sets the stage for upcoming features and examples explored in this book. As you will learn in this chapter, there are various ways to perform the same task, such as creating, saving, and executing programs. Consider using the approaches explored as guidance to determine which options are best for your programming style.

Installing a Python Interpreter

Visual Studio Code supports both Python 2.7 and Python 3.6 or later. Although Python 2.7 support is available, it is recommended you use Python 3.6 or later due to version deprecation. You can confirm the version of Python 3.x installed on your computer with the command python3 --version (Linux/macOS) or py -3 --version (Windows). In addition, it is recommended to add Python to your PATH environment variable so that you can type code . in any folder to start editing files in that particular folder with Visual Studio Code.

Try It Out: Install a Python interpreter for your respective operating system. The recommended installation instructions in this section are summarized for each supported platform.

macOS

On macOS, you'll likely need to upgrade your installed version of Python. It is recommended that ...

Get Visual Studio Code for Python Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.