Setup Visual Studio Code for Python Development

Setup Visual Studio Code for Python Development
Configure VS Code IDE for Python Development – TutLinks

In this tutorial, we will have an overview of an open source IDE VS Code and why we choose to go with it for Python development. We will also see how to setup Visual Studio Code for Python development and configure it for a sample Python based Flask hello world project.

By the end of this tutorial, you will have an understanding on

  • Brief introduction and overview of Visual Studio Code.
  • Why we are choosing VS Code for Python application development.
  • Installation of VS Code Plugins that help ease Python development.
  • Configuring the VS Code Plugins for a simple Flask project.

Overview of Visual Studio Code IDE

Visual Studio Code is an Integrated Development Environment, simply an editor to code, write and debug software applications written in various programming languages. Visual Studio Code is an open-source offering from the Microsoft. VS Code has proven to be the best among any other IDEs in the world of Software Development due to large community, support, vast number of plugins than any other IDE and huge number of downloads. VS Code offers various capabilities with the help of plugins and has been a go to IDE for many software developers.

Why I prefer VS Code for Python Application development

I’m not biased and do not have any affinity towards VS Code. But over the period of time I found myself comfortable using VS Code for developing not just Python Project, but it has also become a go to IDE for C#, JavaScript, PHP and Go language development.

With VS Code, you can build or write software for any programming language and the IDE does not limit itself to any set of software programming language. Be it a Go, Python, C# or Ruby, VS Code allows to develop software with the integrations and plugins available. It has rich set of version control plugins, plugins that help you connect remote servers, powerful debug capabilities to mention a few.

You can customize the editor with preferences and settings or have a different look and feel by choosing various color themes (Ctrl+K Ctrl+T) it offers. VS Code comes with minimal UI and Menus with high control over the GUI aspects of IDE via rich set of customizable keyboard short cuts which most of the developers love. Almost all programming languages has intellisense support offered via respective plugins.

The other popular alternatives to VS Code IDE for Python development are PyCharm, Visual Studio, Atom to mention a few. I will be using Visual Studio Code and will be setting up the IDE for the Python Programming Development.

Configure VS Code IDE for Python Development

We will first install the basic VS Code plugins to help ease our Python development. Later we will configure the installed plugins for the sample Python based Flask project that we want to work.

Install Python Extensions / Plugins for VS Code IDE

Install the following extensions to help you write Python programming on VS Code IDE.

  • ms-python.python extension for Python development that has the capabilities like Linting, Debugging (multi-threaded, remote), Intellisense, Jupyter Notebooks, code formatting, refactoring, unit tests, snippets, and more.
  • eamodio.gitlens, GitLens โ€” Git supercharged extension for Source control management via Git. Here is the description from the official GitLens plugin about what it offers. GitLens supercharges the Git capabilities built into Visual Studio Code. It helps you to visualize code authorship at a glance via Git blame annotations and code lens, seamlessly navigate and explore Git repositories, gain valuable insights via powerful comparison commands, and so much more.
  • donjayamanne.githistory Git History to View git log, file history, compare branches or commits.

You are free to install other extensions you find comfortable working with at any point of time as you explore.

Configure VS Code Plugins for Python

After these extensions are installed, configure the VS Code IDE for Python development.

Please be noted that the following settings need to be done when you are creating a new Python project or on an existing Python project. You also can create a basic Hello World Flask based Python app and try configure Python plugins for VS Code IDE.

You need to create Virtual Environment before you set things up for the VS Code IDE. For that you can refer this detailed tutorial on Working with Virtual Environments in Python for Beginners. Otherwise you can also refer to this video that walks you through the detailed tutorial on How to manage Python projects using Virtualenv

Configure Python Interpreter in VS Code

In the VS Code IDE, hit the keys Ctrl+Shift+P and Type Python:Select Interpreter in the text box prompt that pops up at the top middle of the VS Code IDE to choose Interpreter. Choose the path that points to your virtual environment.

Configure Linter

A Linter is generally a program that does the static code analysis. Linter will help reduce compile time errors that arise due to syntax errors. Every program has its own static code analyzer aka linter and can be installed as an extension if available in VS Code.

In VS Code hit the keys Ctrl+Shift+P and Type Python:Select Linter in the text box prompt that pops up at the top middle of the VS Code IDE to choose linter. Up on hitting enter, choose linter of your choice. Let’s choose pylint.

A file named settings.json will be created with references to Interpreter and Linter. In settings.json file located under .vscode directory at the root of the project.

Ensure you point the python.pythonPath to the virtual environment’s python executable. Also ensure the linter preferences are enabled. On Windows OS, the .vscode\settings.json should look similar as below.

{
    "python.pythonPath": "{your-env-name}\\Scripts\\python.exe",
    "python.linting.pylintEnabled": true,
    "python.linting.enabled": true
}

Check in the .vscode directory to source control

It is a good practice to check the .vscode directory to the source control. Doing so will enforce and ensure all the contributors of this repository will have same settings specific to a project.

Video Tutorial

Setup Visual Studio Code for Python Development – TutLinks

Navule Pavan Kumar Rao

A Full Stack Software Consultant in the day, a Data Scientist in the evening, an Innovative thinker in the nights. Did I forget to say I am a powerful dreamer during the Mid nights? ๐Ÿ˜‰ Education: Executive M.Tech in Data Science, Indian Institute of Technology, Hyderabad. B.Tech in Electronics and Communication Engineering. Hobbies: Games, Music, Creative Thinking
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
trackback
3 months ago

[…] you proceed it is recommended to have a read through of the tutorial that helps you Setup VS Code IDE for Flask Development. Alternatively, to speed things up, you can go through the video tutorial to Get started with […]