Skip to content
Wiki

Setting Up

There are many ways to set up your Python environment with different advantages and disadvantages. This guide will help you get fully setup to start coding in Python.

Local development

This is the most flexible option as you can use any IDE you want and does not rely on an internet connection. This should be done on your personal computer and not on a school computer. This option also has the most complexity and learning due to all advanced features being available immediately. To use this option you will need to install Python and a code editor. You can download Python from the Python website. You can use any code editor you want, but we recommend Visual Studio Code.

Installing Python

There are multiple ways to install Python, but the easiest way is to download the latest version from the Python website. Once you have downloaded the installer you can run it and follow the instructions to install Python.

You can also install python using a package manager for a more advanced setup. If you are using macOS you can use Homebrew to install Python. If you are using Linux you can use your package manager to install Python. If you are using Windows you can use Chocolatey to install Python.

choco install python

Once you have installed Python you can check that it has installed correctly by running the following command:

python --version

You should get an output similar to the following:

Python 3.11.1

Setting up a project

To set up a project you will need to create a new folder for your project. You can then open this folder in your code editor. You will also need to setup the virtual environment for your project. You can do this by running the following command:

poetry init

This will create a pyproject.toml file in your project folder. This file contains all the information about your project and is used by Python Poetry to manage your project. You can then install libraries using Python Poetry.

Adding libraries

You can add libraries to your project by running the following command:

poetry add <library>

Next steps

Using Python Poetry

Useful libraries

There are several libraries that are useful when programming in Python and can help with either style/formatting or type checking.

Style and formatting

These libraries help with formatting and style of your code, they can be used to automatically format your code to a standard style and can also be used to check your code for style errors. They should be added to your style dependencies using the below commands.

You can add them by running the following commands:

poetry add black flake8 --group test
Using Black Formatter

Black is a Python formatter that will automatically format your code to a standard style. You can run Black by running the following command:

poetry run black .
Using Flake8

Flake8 is a Python linter that will check your code for style errors. You can run Flake8 by running the following command:

poetry run flake8 .

Type checking

These libraries help with type checking your code, they can be used to check your code for type errors. They should be added to the test dependencies using the below commands.

You can add them by running the following command:

poetry add mypy --group test
Using MyPy

MyPy is a Python type checker that will check your code for type errors. You can run MyPy by running the following command:

poetry run mypy .

Useful resources