Only registred users can make comments
Aleksandro Matejic

Visual Studio Code Python Configuration

Introduction

Visual Studio Code is a widely used and highly acclaimed code editor among developers. It is recognized for its swift performance and lightweight design, which makes it a go-to option for many developers.

This article will guide you through the process of installing and setting up Visual Studio Code on Mac OS. Whether you're a beginner or an experienced developer, this tutorial will provide you with all the necessary steps to get started with Visual Studio Code on your Mac. From downloading the software to personalizing the settings, we will go through it all in this comprehensive guide. Let's get started with installing Visual Studio Code.

Installation Of Visual Studio Code

To install Visual Studio Code, follow these steps:

  1. Download Visual Studio Code: Visit the official Visual Studio Code website (https://code.visualstudio.com/) and click on the Download button.

  2. Install Visual Studio Code: Run the downloaded file and follow the installation wizard to complete the installation process.

  3. Launch Visual Studio Code: After installation, you can launch Visual Studio Code from the Start menu or from the application folder on your system.

How To Access Settings For Visual Studio Code

You can access the settings for Visual Studio Code in the following ways:

  1. User Settings: User Settings apply to all workspaces and can be found by clicking on the gear icon in the lower left corner of the Visual Studio Code window and selecting "Settings". You can also open the User Settings by pressing Cmd + , on Mac or Ctrl + , on Windows/Linux.

  2. Workspace Settings: Workspace Settings apply only to the current workspace and can be found by opening the Command Palette (Cmd + Shift + P on Mac or Ctrl + Shift + P on Windows/Linux), typing "Settings" and selecting "Preferences: Open Workspace Settings".

Both User Settings and Workspace Settings are stored in JSON format and can be edited directly in the editor. You can use the search bar in the Settings editor to quickly find a specific setting, or browse through the categories on the left to explore the available settings.

The main difference is that User Settings apply globally to all workspaces, while Workspace Settings apply only to the current workspace. This allows you to have different configurations for different projects, while still having a default set of configurations that apply to all projects.

Configuration  For Python

  1. Python interpreter: Select the Python interpreter that you want to use by setting the python.pythonPath in the User or Workspace settings.

  2. Linting: Enable linting by installing the Pylint or flake8 linter and configure it by setting python.linting.pylintEnabled or python.linting.flake8Enabled.

  3. Formatting: Set the default formatter to autopep8 or black by setting python.formatting.provider in the User or Workspace settings.

  4. Code completion: Enable code completion by setting "editor.quickSuggestions" to true.

  5. Code navigation: Enable code navigation features like Go to Definition and Peek Definition by setting "editor.gotoLocation.multipleDefinitions" to "peek".

  6. Debugging: Enable debugging by installing the Python extension and configure it by setting "python.pythonPath".

  7. Testing: Enable testing by installing the Python Test Explorer extension and configure it by setting "python.testing.unittestEnabled" to true.

Visual Studio Code Extensions

Here are some suggestions of known Visual Studio Code extensions:

  1. Python: The official Microsoft Python extension provides IntelliSense, debugging, code navigation, code formatting, testing, and more.

  2. Pylance: A new language server for Python, providing fast and accurate IntelliSense, code navigation, and error checking.

  3. Code Runner: This extension allows you to quickly run code snippets in various programming languages, including Python, directly from the editor.

  4. Auto PEP 8 Format: Automatically formats your code to match the PEP 8 style guide for Python code.

  5. Pytest: An extension that integrates the Pytest testing framework with Visual Studio Code, providing testing assistance and code navigation.

  6. MagicPython: Syntax highlighting and indentation for Jupyter notebooks, Python files, and other documents that use the Python language.

  7. Visual Studio IntelliCode: AI-assisted code completion that provides smart suggestions based on your code and the most common code patterns in your workspace.

  8. GitLens: Adds Git information to the editor and provides insights into the code, making it easier to understand code changes and history.

These are just a few of the many extensions available for Python development in Visual Studio Code. You can browse the Visual Studio Code marketplace to find additional extensions that meet your specific needs.

About the Author

Aleksandro Matejic, a Cloud Architect, began working in the IT industry over 21 years ago as a technical specialist, right after his studies. Since then, he has worked in various companies and industries in various system engineer and IT architect roles. He currently works on designing Cloud solutions, Kubernetes, and other DevOps technologies.

In his spare time, Aleksandro works on different development projects such as developing devoriales.com, a blog and learning platform launching in 2022/2023. In addition, he likes to read and write technical articles about software development and DevOps methods and tools. You can contact Aleksandro by visiting his LinkedIn Profile.

Comments