Lesson 1: PIP, Gunicorn, Procfile, Requirements
Master the essential tools for Python package management, web application deployment, and project documentation.
Lesson Objectives
- Learn what a requirements document is and why it's important for Python projects
- Understand what pip is and how it helps manage Python packages
- Discover what Gunicorn is and how it serves web applications
- Explore what the Procfile is and how it helps deploy applications
Watch: PIP, Gunicorn, Procfile, Requirements Tutorial
PIP, Gunicorn, Procfile, Requirements - Notes
1. Requirements Document (requirements.txt)
Purpose: Stores a list of all the libraries used in your project, including their version numbers.
Format:
Example → flask==3.1.0
(Uses two equal signs == to specify version.)
How it gets filled:
- When you install a library, it isn't automatically added.
- To update it, run:
pip freeze > requirements.txtThis captures all libraries from the virtual environment and writes them into the file.
Example: Adding MySQL
Install the library:
pip install mysqlclientUpdate requirements file:
pip freeze > requirements.txtNow you'll see mysqlclient listed inside requirements.txt.
Important Notes
- Using Tab Autocomplete helps avoid typos and ensures the file exists.
- Running
pip freezemay capture many extra libraries in your virtual environment. That's normal—it just means everything needed for your project will be listed.
2. Pip (Python Package Installer)
Definition: Tool used to install libraries in Python.
Command format:
pip install <library_name>Connection to requirements.txt:
Pip installs → pip freeze saves the list → requirements.txt keeps track of them.
3. Procfile
Location: Must exist in the root directory of your project.
Purpose: Tells Heroku which web server to run.
Format:
web: gunicorn app:appweb:→ process type (web server).gunicorn→ server used by Heroku.app:app→ points to your Flask app (app.py → Flask instance called app).
Important Notes
Procfile must:
- Start with a capital P.
- Have no file extension.
- Be spelled exactly as Procfile.
4. Gunicorn
- A lightweight Python web server.
- Required by Heroku to serve your Flask app.
- Must appear in requirements.txt (use
pip installif missing):
pip install gunicorn Key Takeaways
- requirements.txt: Tracks all libraries and versions (use
pip freezeto update). - pip: Installs libraries (e.g., Flask, MySQL, Gunicorn).
- Procfile: Instructs Heroku which server to run (
gunicorn app:app).
Always double-check:
gunicornis installed and listed in requirements.txt.- Procfile is formatted correctly and has no extension.