$ command-helper

Python: pip, venv, uv

Virtual environments, installing packages, requirements, uv, handy one-liners.

Requires Google sign-in

Virtual environments

Create a virtual environment
python3 -m venv .venv
Activate it
source .venv/bin/activate

Windows: .venv\Scripts\activate · leave with deactivate

Which Python is used
which python && python --version

pip

Install a package
pip install <package>
Install from requirements.txt
pip install -r requirements.txt
Freeze installed packages
pip freeze > requirements.txt
Install the current project in editable mode
pip install -e .
Outdated packages
pip list --outdated
Package info and dependencies
pip show <package>

uv

New project
uv init <project>
Add a dependency
uv add <package>
Install everything from the lockfile
uv sync
Run a command in the project environment
uv run <script>.py
Run a CLI tool without installing
uvx <tool>
Install a specific Python versionadvanced
uv python install 3.13

One-liners

Serve the current directory over HTTP
python3 -m http.server 8000
Pretty-print JSON
python3 -m json.tool <file>.json
Profile a scriptadvanced
python3 -m cProfile -s cumtime <script>.py
Start the debugger at a crashadvanced
python3 -m pdb -c continue <script>.py
Run tests (pytest), stop at the first failure
pytest -x -q