Start learning free

LESSON 147 OF 188 · BACKEND: SHIPPING IT

requirements.txt

Practice

On your computer, the shop runs with the packages you installed one day with pip install. A server starts empty. It installs the packages listed in a file named requirements.txt: one package per line, written name==version.

The == pins the version: pip installs exactly that version, on every machine, not whatever is newest on the day it runs. Modules that come with Python, like sqlite3 and json, stay out of the file: they aren't packages pip can install. Here is the file of another project, a small bot that sends a newsletter:

requests==2.32.3
schedule==1.2.2

In this lesson the file's text is a Python string, requirements, written as one piece per line inside parentheses. Each piece ends with \n, a line break, so every package gets its own line. The check reads the text the way pip would and prints:

requirements.txt:
Flask==3.1.3
gunicorn==23.0.0
requests==2.34.1
pip install -r requirements.txt:
Flask 3.1.3: this exact version, on every machine
gunicorn 23.0.0: this exact version, on every machine
requests 2.34.1: this exact version, on every machine
The shop needs Flask (app.py imports flask): pinned to 3.1.3
The shop needs gunicorn (the server runs the shop with it): pinned to 23.0.0
The shop needs requests (the shop calls the supplier and payments with it): pinned to 2.34.1

Your task: pin the three packages the shop needs on a server, one per line: Flask 3.1.3, gunicorn 23.0.0 (the web server that will run the shop) and requests 2.34.1.


Assignment
Follow the Coding Tutorial to write requirements, the text of the shop's requirements.txt, with one pinned package per line.


Hint
Each line is the name, ==, the version and \n, all inside one pair of quotes. Pieces written side by side inside the parentheses join into one string.


STEP 1 OF 3
    Ctrl + Enter to check