python course for today

Words
308
Reading
2 min
6h
Listen to this post
~2 min

At its core, it’s the same command, but the underlying logic is completely different.

  1. pip install package (one by one)
    When you run:

Bash
pip install fastapi
pip install uvicorn
pip install sqlalchemy
You are installing packages on the fly, always grabbing the latest available version. Pip resolves dependencies on a case-by-case basis.

Problems:

You have no control over versions. Tomorrow, on a different PC, a new major version of fastapi might be released that breaks your code.
Hidden conflicts. If you install package A, and then package B, which requires a different version of A, pip will overwrite A without giving you a clear warning.
Impossible to reproduce. If you need to reinstall your project in three months—or share it with someone else—you won’t remember exactly what you installed.
This approach is fine for quick, one-off tests in a notebook.

  1. pip install -r requirements.txt
    In this case, your file looks like this:

Code
fastapi0.110.0
uvicorn[standard]0.29.0
sqlalchemy==2.0.29
And you run:

Bash
pip install -r requirements.txt
Advantages:

a) Global resolution. pip reads the ENTIRE file first, then resolves all dependencies collectively. This is far more likely to result in a compatible combination of packages than installing them one by one.

b) Reproducibility. The == syntax locks the versions. Whether you’re in Sousse, Paris, or working on a server, you’ll have the exact same environment. This is essential for teamwork and deployment.

c) Automation. One command can install 50 packages. This is the standard approach for CI/CD pipelines, Docker, etc.

d) Project documentation. The requirements.txt file acts as a list of ingredients for your project—it clearly defines what the project needs to run. In practice, the professional workflow looks like this:

You work within a virtual environment (venv).
You install packages one by one as you develop—for example: pip install fastapi.
Once everything is working, you lock the dependencies: pip freeze > requirements.txt.
From that point on, everyone else installs the dependencies using pip install -r requirements.txt.

python course for today | Ecency