2c Activity: Python Project Management

Goal

We will add a small pyproject.toml file to the same practice repository, list a few packages, install them, pin the versions we care about, and test the environment in a notebook.

Note: The checkboxes on this page are only stored locally in your browser. They are not submitted or synced anywhere.

Progress: 0 / 0 steps complete.

Activity

Open the python_tmr_practice repository in Codespaces.

This should be the same repository you used for 2a and 2b.

In the Explorer, create a file named pyproject.toml at the top level of the repository.

There are tools that can generate a starter pyproject.toml, such as uv init, Poetry, and Hatch. For this activity, we will write a very small one ourselves so we can see exactly what each piece does.

Add this starter content:

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "python-tmr-practice"
version = "0.1.0"
requires-python = ">=3.13"
dependencies = [
    "ipykernel",
    "nbformat",
    "pandas",
    "plotly",
    "polars",
]

[tool.setuptools]
py-modules = []

Save the file.

Notice the pieces:

  • name: the project name;
  • version: a project version;
  • requires-python: the Python version expectation;
  • dependencies: Python packages the project needs;
  • tool.setuptools: a small setting that says this practice project does not define an importable Python package.

Right now the dependency list names the packages we want, without requiring exact versions. This file stores the project configuration, but it does not install anything just by existing.

Open a terminal and run:

python -m pip install -e .

This installs from the project file. Since the dependency list does not specify exact versions yet, pip will choose current compatible versions.

Then check that Polars imports:

python -c "import polars as pl; print(pl.__version__)"

After installing, ask Python what is installed:

python -m pip freeze

The terminal will print a long list of installed packages. We are using this as a readout, not saving it to a file.

Find the lines for the packages we intentionally installed:

ipykernel==...
nbformat==...
pandas==...
plotly==...
polars==...

Edit the dependencies part of pyproject.toml so it looks like this, using the version numbers from your terminal:

dependencies = [
    "ipykernel==...",
    "nbformat==...",
    "pandas==...",
    "plotly==...",
    "polars==...",
]

Do not copy every package from pip freeze. Many of those are packages that our chosen packages need. The installer can solve those later.

The file now records the packages this project needs and the versions we want to keep using.

Run:

python -m pip install -e .

In this Codespace, most of the work may already be done. The important point is that pyproject.toml is now a recipe that a future environment can use.

Create a new notebook named environment_check.ipynb.

If VS Code asks you to choose a kernel, choose the Python environment for this Codespace.

In the first code cell, paste and run:

import pandas as pd
import plotly.express as px
import polars as pl

print("Polars:", pl.__version__)
print("pandas:", pd.__version__)

In a second code cell, paste and run:

sample_pl = pl.DataFrame(
    {
        "year": [2022, 2023, 2024],
        "projects": [1, 2, 4],
    }
)

sample_pd = pd.DataFrame(
    {
        "year": [2022, 2023, 2024],
        "projects": [1, 2, 4],
    }
)

total_projects = sample_pl.select(pl.col("projects").sum()).item()
print("Total projects:", total_projects)

fig = px.line(
    sample_pd,
    x="year",
    y="projects",
    markers=True,
)
fig.show()

Use Source Control:

  1. Review the changes.
  2. Find pyproject.toml and environment_check.ipynb under Changes.
  3. Hover over each file and click the + button to stage it.
  4. Confirm that the files moved from Changes to Staged Changes.
  5. Commit with a message such as:
Added Python project environment files.

Push or sync the commit to GitHub.