Use this when installing Python packages.
pip
pip installs Python packages from PyPI, such as pip install requests. Pin versions in requirements.txt and install inside a virtual environment rather than system-wide.
1. pip installs packages.
2. Pin versions (== or lock files with hashes).
3. Audit for vulnerabilities.
4. Use private indexes carefully (dependency confusion).
5. --break-system-packages only when necessary.
requirements → pip → venv
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Common mistakes Narrow the fault
sudo pip installinto the system Python.- Unpinned versions changing behaviour between runs.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Install packages inside a virtual environment.
- Pin versions in requirements.txt.
- Use pip install -r to reproduce.
pip install -r requirements.txt— install pinnedpip list --outdated— updatespip-audit— vulnerable packages
ReferenceWhy it matters1 section · depth on demand
What it is
pip installs Python packages from PyPI or other indexes. Pin versions in requirements.txt (or a lock file) so every run uses the same code.
ReferenceImportant terms & boundaries3 sections · depth on demand
In depth
pip installs Python packages from PyPI or other indexes. For automation the important part is reproducibility: the same script must get the same library versions on a laptop, a CI runner and the automation server.
python3 -m venv .venv && . .venv/bin/activate
python -m pip install --upgrade pip
pip install -r requirements.txt
pip freeze > requirements.lock # exact versions actually installed
pip install --require-hashes -r requirements.lock # with hashes: tamper-proof installs
Good practice: always install into a virtual environment (never sudo pip into the system Python; recent distributions block this with "externally-managed-environment"), pin versions, and use an internal mirror or proxy where servers have no internet access. pipx installs command-line tools such as ansible-lint in isolated environments.
Example
pip install 'netmiko==4.4.0'
pip freeze > requirements.txt
pip install -r requirements.txt
pip-audit
Mechanics
The linked authority for bounded mechanics is Python 3 Documentation; documentation support is separate from observed lab/production Evidence.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Python Automation > pip. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://docs.python.org/3/ · confidence 94%