PP Read 1-Python in Visual Studio Code
PP Read 1-Python in Visual Studio Code
Working with Python in Visual Studio Code, using the Microsoft Python extension, is simple, fun, and
productive.
The extension makes VS Code an excellent Python editor and works on any operating system with a variety
of Python interpreters.
It leverages all of VS Code's power to provide autocomplete and IntelliSense, linting, debugging, and unit
testing, along with the ability to easily switch between Python environments, including virtual and Conda
environments.
Step 0: Prerequisites
Specifically, this tutorial requires:
VS Code
VS Code Python extension
Python
After successful installation, you may see an interface like the one above.
Put the last button on the right-hand side Extensions OR you can use the shortcut key Ctrl + Shift + X to
get the Extensions Market.
(Optional)
Search with the keyword Chinese, download the first extension Chinese.
1.2
Next, install the Python extension for VS Code from the Visual Studio Marketplace, using the keyword Python
The extensions set varies from person to person. But I recommend some basic extensions as follows:
Kite
Beautify
Python Indent
Python Indent
Jupyter
Prettier - Code formatter
(optional) latex
(optional) Python Environment Manager
Install Python from python.org. You can typically use the Download Python button that appears first on the
page to download the latest version.
Note: The page provides installs of Python 3.7, Python 3.8, Python 3.9, and Python 3.10. Be aware that
Python 3.7 is required in SI100.
For additional information about using Python on Windows, see Using Python on Windows at Python.org
py -3 --version
cd Desktop
mkdir SI100
cd SI100
code .
VS Code stores settings that are specific to that workspace in .vscode/settings.json , which are separate
from user settings that are stored globally.
Alternately, you can run VS Code through the operating system UI, then use File > Open Folder to open the
project folder. (which means to 打开文件夹)
The path to your workspace is decided by yourself, but managing your different workspace decently is a
good habit.
From within VS Code, select a Python 3 interpreter by opening the Command Palette ( Ctrl+Shift+P ), start
typing the Python: Select Interpreter (Python:选择解释器) command to search, then select the
command.
You can also use the Select Python Environment option on the Status Bar if available (it may already show
a selected interpreter, too):
print("Hello world")
When you start typing print , notice how IntelliSense presents auto-completion options. It provides
completions for methods available on object types.
By using the .py file extension, you tell VS Code to interpret this file as a Python program, so that it evaluates the
contents with the Python extension and the selected interpreter.
Note: the File Explorer toolbar also allows you to create folders within your workspace to better
organize your code. You can use the New folder button to quickly create a folder.
Step 7: Run Your First Python File
It's simple to run test.py with Python. Just click the Run Python File in Terminal play button on the top-
right side of the editor.
In Python, packages are how you obtain any number of useful code libraries.
For this example, you use the matplotlib and NumPy packages to create a graphical plot as is commonly
done with data science, which is in the syllabus.
About
Author: Kyran Fang
Date: 02/17/2022