Visual Studio Code is an open-source, customizable, lightweight editor available across all platforms and one of the best Python Online Compilers accessible to programmers. Because of these features, Microsoft’s Visual Studio Code is incredibly well-liked and a great environment for Python development.

This post will show you how to build, run, and debug Python script code files using Visual Studio Code.

  1. To Install The Python Extension For Visual Studio Code.
  1. Click on View and select the Extensions menu option from the menu bar of Visual Studio Code. The EXTENSIONS panel on the left side of Visual Studio Code will display a list of all installed and suggested extensions.
  2. To install the Python extension made by Microsoft, type “python” into the search bar and press the Install button.
  3. You must restart Visual Studio after you install the Python extension Code for it to take effect.
  4. However, you must ensure the Python interpreter has been appropriately installed on your OS before you begin writing and debugging Python code in Visual Studio Code.
  1. In Visual Studio Code, choose the installed Python interpreter.
  1. Click on the View and press the Command Palette button after starting Visual Studio Code.
  2. Type in the word “Python” and click Interpreter on the popup window that appears after you make your selection.
  3. It will then show every Python interpreter installed on your OS (the path to the python .exe file). One of these can be chosen to execute the Python script file afterward.

 

  1. Python Script Code File Development with Visual Studio Code.
  1. Make a folder on your operating system that will serve as the Visual Studio Code workspace for the Python project.
  2. Select Open Folder under File. In the folder, browse dialogue, select the newly created folder, and press the Open button. On the left side pane of Visual Studio source Code, which has the same name as the folder name in capital letters, all the files inside the folder will then be listed.
  3. To create a new python file, either right-click the folder name and choose New File from the popup menu list or click the New File button in the upper right corner of the folder pane. Ensure the File has a .py extension at the end.
  4. Tap the filename. The File will open in a new window on the right.
  5. You can now enter the Python code shown below in the newly built Python file.

msg = ‘I love python’

print(msg)

  1. How You Can Use Visual Studio Code To Execute The Python Script File.
  1. A menu list will appear when you right-click the source code of the Python source file in the editor.
  2. A few menu options allow you to run and execute the Python code in various settings.
  3. The Run and execute the Python Script in Terminal menu option launches the Terminal built into Visual Studio Code and executes the python code.
  4. When you select this menu item, the TERMINAL screen at the base of the visual studio code will appear. Then open the Terminal and execute the python file.
  5. The TERMINAL window displays the result text you can see below.

/usr/local/bin/python3 /Users/songzhao/Documents/WorkSpace/PythonExample/test.py

The default interactive shell is now zsh.

To update your account to use zsh, please run `chsh -s /bin/zsh.`

For more details, please visit https://support.apple.com/kb/HT208050.

(base) songs-MacBook-Pro:PythonExample songzhao$ /usr/local/bin/python3 /Users/songzhao/Documents/WorkSpace/PythonExample/test.py

I love python

  1. Select Terminal > New Terminal / Split Terminal to open a new TERMINAL window on the top menu bar.
  2. An interactive window will open on the right-hand side of the Visual Studio code once you right-click the Python source file and choose Run Existing File in the Interactive Window from the popup menu list.
  3. A text line is present. To run the code in a dark blue region at the bottom of the interactive window, type it here and press shift-enter.
  4. To execute the Python code, insert the source code and click Shift + Enter.
  5. You can view the Python code running the result in the active window top area.
  6. When you simultaneously press the Shift and enter keys, the interactive window’s top area will show both the result and the Python source code.

also read:  Php Vs Python: Which Is Best For Web Development?

  1. Python Source Code Debugging with Visual Studio Code.
  1. To establish a breakpoint, click the first column of a Python source code line.
  2. To begin debugging, click on Visual Studio Code Run and select the Start Debugging menu item in the menu bar.
  3. The command palette window will now be opened. Choose Python File Debug the currently active Python file from the drop-down list.
  4. The first breakpoint will cause the Python program to terminate.
  5. To debug the Python code, click on Continue, Step Into, Step Over, Step Out, Restart, and Stop buttons on the debug toolbar.