Python: pip, venv, uv
Virtual environments, installing packages, requirements, uv, handy one-liners.
Virtual environments
Create a virtual environment
python3 -m venv .venvActivate it
source .venv/bin/activateWindows: .venv\Scripts\activate · leave with deactivate
Which Python is used
which python && python --versionpip
Install a package
pip install <package>
Install from requirements.txt
pip install -r requirements.txtFreeze installed packages
pip freeze > requirements.txtInstall the current project in editable mode
pip install -e .Outdated packages
pip list --outdatedPackage info and dependencies
pip show <package>
uv
New project
uv init <project>
Add a dependency
uv add <package>
Install everything from the lockfile
uv syncRun 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.13One-liners
Serve the current directory over HTTP
python3 -m http.server 8000Pretty-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