Cheat Sheet Library

pip & Python venv Cheat Sheet

Always use a virtual environment per project so packages don't clash. On Windows, py is the Python launcher. On Linux/macOS use python3.

  • 43 entries
  • 8 sections
  • Updated
  • Click a command to see all its options

43 entries

On this page

Create & Activate a venv #

TaskCommand
Create
Create with a specific version (Windows)
Activate: PowerShell.venv\Scripts\Activate.ps1
Activate: cmd.venv\Scripts\activate.bat
Activate: Git Bash
Activate: Linux / macOS
Deactivatedeactivate
Check which Python is active
DeleteDelete the .venv folder

Debian/Ubuntu need the venv module first: sudo apt install python3-venv.

pip Basics #

CommandAction
Install
Exact version
Version range
Upgrade
Remove
Installed packages
Packages with updates
Details and location
Save exact versions
Install from a file
Install your own project in editable mode
Detect broken dependencies
Clear the download cache
Upgrade pip itself

Use python -m pip instead of pip when you are unsure which Python the pip command belongs to.

Windows Python Launcher #

CommandAction
Latest installed Python
Run with a specific version
Installed versions

pipx (CLI tools globally, isolated) #

CommandAction
Install a CLI tool in its own environment
Installed tools
Update all
Run once without installing

uv (fast, modern alternative) #

CommandAction
New project with pyproject.toml
Add a dependency (creates .venv automatically)
Remove
Install everything from the lockfile
Run inside the project's environment
Create a venv
pip-compatible install (much faster)
Install a Python version
Run a tool once (like pipx run)

Minimal pyproject.toml #

[project]
name = "my-app"
version = "0.1.0"
requires-python = ">=3.11"
dependencies = [
    "requests>=2.32",
]

Common Errors #

ErrorFix
externally-managed-environment (Debian/Ubuntu)Use a venv or pipx, not the system Python
Activate.ps1 cannot be loadedSet-ExecutionPolicy -Scope CurrentUser RemoteSigned
ModuleNotFoundError after installingThe venv is not active, or the editor uses another interpreter (VS Code: Python: Select Interpreter)
not foundUse /

Tips #

  • Add .venv/ to .gitignore. Commit requirements.txt or pyproject.toml + lockfile instead.