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

``

# 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

Connecting Azure Data Studio to Postgres

Connecting Azure Data Studio to Postgres

  • 2024-05-09
  • 2 minutes to read

How to connect Azure Data Studio to a Postgres database.

Read More
Creating a Postgres docker container and connecting dbt

Creating a Postgres docker container and connecting dbt

  • 2024-05-09
  • 5 minutes to read

How to get started with dbt and the Postgres adapter.

Read More
Setting up the dbt SQL Server Adapter

Setting up the dbt SQL Server Adapter

  • 2024-05-09
  • 6 minutes to read

How to get started with dbt and the SQL Server adapter including fixing issues on macOS.

Read More