3. Create a Data Science Project with uv

Duration1h30 AI Banned

Introduction

You will now create the Sales project from an empty directory. Rather than copying a prepared environment, you will ask uv to define the project, install Python, declare its dependencies, create an isolated environment, and lock the selected package versions. This is the same workflow you will use to reproduce and maintain later data science projects.

Create the project directory

Open the workspace created in the previous activity and run:

1
2
3
4
cd ~/data-science-toolkit
mkdir sales-analysis
cd sales-analysis
uv init --bare

The --bare option creates only the minimal pyproject.toml required by uv. You will add the structure that is relevant to a notebook project yourself.

Create the project directories and its initial documentation:

1
2
mkdir -p data notebooks/images
touch README.md

Your project should now look like this:

1
2
3
4
5
6
sales-analysis/
├── README.md
├── data/
├── notebooks/
│   └── images/
└── pyproject.toml
Checkpoint 1

Run pwd and ls -la. You must be inside sales-analysis, and pyproject.toml must be visible before you install Python or any library.

Select the Python version

Install and pin Python 3.12 for this project:

1
2
uv python install 3.12
uv python pin 3.12

The pin command creates .python-version. This small text file tells uv and other tools which Python version the project expects.

Check the selected version:

1
2
cat .python-version
uv run python --version

The first uv run also creates the project environment in .venv if it does not already exist.

Add the project dependencies

Add the libraries required by the Sales analysis:

1
uv add pandas numpy matplotlib seaborn scipy

Add ipykernel as a development dependency so that VS Code can execute the notebook with this environment:

1
uv add --dev ipykernel
Dependencies and development dependencies

The analysis libraries are direct project dependencies because the notebook needs them to run. ipykernel is a development tool used to connect the project environment to an interactive notebook, so uv records it in the dev dependency group. A dependency group is not an optional extra: do not use --extra dev.

Open pyproject.toml in VS Code and identify:

  • the project name and version;
  • the required Python version;
  • the main dependencies list;
  • the dev dependency group.

Understand the generated environment

After adding the dependencies, the project contains four important uv elements:

Element Role Tracked by Git later?
pyproject.toml Declares the project and its direct dependencies Yes
.python-version Records the expected Python version Yes
uv.lock Records the exact resolved dependency versions Yes
.venv/ Contains the local Python environment and installed packages No

uv add updates pyproject.toml, resolves the dependencies, updates uv.lock, and synchronizes .venv. You can explicitly request the same synchronization later with:

1
uv sync --locked

The --locked option checks that uv.lock agrees with pyproject.toml instead of silently changing the lockfile.

Validate the project

Run Python through uv and inspect the active executable:

1
2
3
4
uv run python --version
uv run python -c "import sys; print(sys.executable)"
uv run python -c "import pandas; print(pandas.__version__)"
uv tree

The executable path must point to .venv/bin/python inside sales-analysis.

Checkpoint 2

The project contains pyproject.toml, .python-version, uv.lock, and .venv; pandas imports successfully; and sys.executable points to the project .venv.

Initialize the README

Open README.md in VS Code and add the following structure. You will complete it as your analysis progresses.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# Sales Analysis Project

## Business Context

[Summarize the retailer's problem.]

## Dataset

[Describe the available sales data.]

## Research Questions

[Add the questions developed in Activity 1.]

## Main Findings

[Complete this section during the analysis.]

## Reproducing the Analysis

[Document the commands needed to recreate and run the project.]
Activity complete

Your Sales project has been built from an empty directory and can run Python through uv. In the next activity, you will connect this environment to a notebook in VS Code.