Getting Started With Python in Vscode

Getting Started With Python in Vscode

  • coding
  • 2024-04-05
  • 2 minutes to read

Introduction

In this post, I will talk through how to install and configure Python in Vscode. Vscode is my swiss army knife for coding, and I try to use it for all my coding projects. It is a powerful code editor that is highly customisable and has a vast array of extensions that can be installed to enhance its functionality.

Check if Python is installed

First step is to check if Python is installed on your machine. Open a terminal and type the following command:

# this command will work on Windows too
python3 --version

This will check whether you have Python 3 installed. Note that Python 2 is no longer supported, so it is essential to have Python 3 installed for any new projects. You can confirm whether you have Python 2 installed by running the command python --version.

Installing Python

You can install Python from the official website or with the help of Homebrew:

## command is macOS
brew install python

## commands for Windows
# see what versions of Python is available
winget search python.python
# then install the version you want for example...
winget install python.python.3.12

Extensions

The main extension to install is the Python extension by Microsoft:

Some other extensions I have been using are:

  • autoDocstring which generates python docstrings automatically
  • Flake8 by Microsoft which offers linting support for Python files using Flake8.
  • IntelliCode by Microsoft which offers AI assisted code completion

Write your first Python script

Create a new file in Vscode and save it with a .py extension. You can then write your first Python script. You can then run the script by pressing the play button in the top right corner of the editor.

A simply Python script in Vscode

Conclusion

In this post, I have talked through how to install and configure Python in Vscode. I have also identified some of the useful extensions to install. I hope this post has been helpful, and you are now ready to start coding in Python in Vscode.

#mtfbwy



Recent Posts

How to Search for a Lost File in the Git Log

How to Search for a Lost File in the Git Log

  • 2024-04-27
  • 4 minutes to read

I have lost a file in my Git repository. How can I find it by searching the git log?

Read More
No Such Shell Function 'Zle Line Init' in Zsh

No Such Shell Function 'Zle Line Init' in Zsh

  • 2024-04-25
  • 3 minutes to read

Troubleshooting the error message "no such shell function 'zle line init'" in zsh when using OhMyPosh.

Read More
Microsoft Certified: Azure Solutions Architect Expert

Microsoft Certified: Azure Solutions Architect Expert

  • 2024-04-03
  • 2 minutes to read

Information on passing the AZ-305 exam and earning the Azure Solutions Architect Expert certification.

Read More