Getting Started With Python in Vscode

Getting Started With Python in Vscode

  • coding
  • 2024-04-05
  • 2 minutes to read
Table of Contents

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

``

# create a virtual environment:
python3 -m venv ~/python/main
# to use the virtual environment, it needs to be activated:
source ~/python/main
# now you can install packages in the virtual environment:
python3 -m pip install cowsay

`

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

Hugo Live Reload Keeps Reloading

Hugo Live Reload Keeps Reloading

  • 2024-05-18
  • 3 minutes to read

I have run into an issue from time to time where Hugo's live reload feature keeps reloading the page. This is how I fixed it.

Read More
First Steps with Mermaid in Vscode

First Steps with Mermaid in Vscode

  • 2024-05-17
  • 7 minutes to read

My blog theme supports mermaid, a visual diagram syntax, so I wanted to try it out in vscode.

Read More
T-SQL Tuesday #174 My favourite job interview question

T-SQL Tuesday #174 My favourite job interview question

  • 2024-05-14
  • 4 minutes to read

This is my 12th contribution to TSQL Tuesday, the data community blog party. Have a read, and why not join in next time!

Read More