VS Code for Python Developer (Windows):
Prerequisite: Python 3 and VS Code must be installed in your system.
A. Configuring Project Folder:
1. Python extension for Visual Studio Code:
In the extensions window search for Python extension by Microsoft an install it.
Figure 1: image-20200505205901494
2. Open Project Folder:
Open project folder from explorer window( ctrl + shift + E).
Folder can be opened from File menu.
3. Open New Terminal for Virtual Environment Setup
New Terminal keyboard shortcut for windows: Ctrl + Shift + ~
There are several terminal shells available an you can set default shell.
By default PowerShell is selected. You can change it to Command Prompt.
4. Creating and Activating Virtual Environment:
Create Virtual Environment
1
Figure 2: image-20200505192005830
python -m venv ve
Here ve is the name of the environment and it can be any name.
Activate Virtual Environment:
.\ve\Scripts\activate.bat
Install Package in Virtual Environment: pip or pip3 command used to
install new packages in the virtual environment.
pip3 install *package
Here *package will be the name of the package to be installed.
#### Deactivate Virtual Environment:
In order to deactivate the virtual environment use the following command.
deactivate
5. Select the Python Interpreter:
Press Ctrl+Shift+P to brings up the Command Palette
Insert following command in the Command Palette to choose the virtual env.
Python Interpreter.
2
Figure 3: image-20200505190423149
3
Figure 4: image-20200505190834489
4
Figure 5: image-20200505191401388
Figure 6: image-20200505210358302
Figure 7: image-20200505210516240
5
Figure 8: image-20200505191605310
Figure 9: image-20200505192233786
6
Figure 10: image-20200505194930165
Python: Select Interpreter
Figure 11: image-20200505195738576
Check the settings.json file’s configuration.
6. Configuring Debugger:
Open debugger window (Run Ctrl + Shift + D) and create a launch.json file.
Select Environment: Python
Select a debug configuration: Debug the currently active Python file.
Insert the following line of code (will discuss about it is debugging section)
"stopOnEntry": true
7
Figure 12: image-20200505202957033
Figure 13: image-20200505194445370
8
Figure 14: image-20200505200208427
Figure 15: image-20200505200328422
Figure 16: image-20200505200941165
9
B. Create and Edit Python Files:
C. Format Code:
pip3 install autopep8
Figure 17: image-20200505212233638
10