pip installs Python packages and dependencies inside a project’s virtual environment. Running it through that environment’s Python interpreter avoids accidentally using a globally installed copy. section 2.1.1
A practical pip workflow:
- Create and activate a virtual environment before installing project dependencies. section 2.1.1
- Upgrade pip, then install individual packages such as FastAPI with python -m pip install. section 2.1.1
- Record packages in requirements.txt and install them together with python -m pip install -r src/requirements.txt. section 2.1.1
- Use a project-specific Python version when preparing dependencies for deployment. section 3.4
FastAPI dependency file
A requirements.txt file can list fastapi, jinja2, uvicorn, and gunicorn. pip then installs the complete set rather than requiring each package to be entered separately. section 2.1.1
Listing 2.6 Installing all third-party packages
# navigate to root of our project where the venv folder lives cd ~/Dev/roadtok8s/py/ # activate or reactivate your virtual environment source venv/bin/activate # or .\venv\Scripts\activate # install all packages via the newly created requirements file python -m pip install -r src/requirements.txt
Shows the command sequence for activating a project environment and installing every dependency declared in requirements.txt. section 2.1.1


