Create and configure a virtual environment for your project

This activity assumes you have already completed tutorial 2 and the week 1 coursework activity to create the repository.

Carry out the following:

1. Create and activate a Python virtual environment in the directory of the project

There are several tools that allow you to create Python virtual environment in a project such as Python venv, pipenv and poetry. You may use any.

venv comes with Python so the following should work for all.

There are specific instructions for each IDE using their menu options to create a virtual environment:

Otherwise, you can use the PyCharm/VS Code Terminal with the following guidance.

Create a virtual environment

To create a virtual environment, open the Terminal in your IDE (VS Code, PyCharm). Check that you are in the directory of the project, if not, navigate to it.

Enter the code to create the "venv" in the Terminal.

The command will take a few minutes to complete.

Activate the virtual environment

You now need to activate the virtual environment for the current project.

2. Install the dependencies in the environment

For the coursework1 you will need pandas. For coursework2 you will need pytest. These are listed in requirements.txt

Find the correct syntax for your operating system

Install the dependent libraries/packages using requirements.txt, e.g.: pip install -r requirements.txt

3. Understand the purpose of the project files

Aside from the coursework starter files, there are some essential files that you need to set up your project's code. You need to understand their purpose. These are:

4. Install the code in this repo in your environment

This is needed in coursework 2; however for convenience it is recommended you complete the step now.

Installing your code as a package in the following way means that any changes you make to the code will affect the installed package without needing to re-install it.

This process requires a configuration file about the project such as pyproject.toml, setup.cfg or setup.py.

This repository has a pyproject.toml configuration file.

Enter the code for your operating system in the Terminal of the project's root folder in your IDE.

pip install --editable . or pip install -e .

The . is not a typo, it is required. It refers to anything in the current directory tree in the command prompt of the terminal.