Skip to main content

Python pip install quick reference. Also include pip command usage in venv, vs system-installed Python.

# Python `pip` Install Cheatsheet

## Install / Upgrade / Remove

```bash
python3 -m pip install package_name           # install latest
python3 -m pip install package_name==1.2.3    # install specific version
python3 -m pip install --upgrade package_name
python3 -m pip uninstall package_name

# Or to ensure a package is installed in homebrew installed python, and not macOS installed python
/opt/homebrew/bin/python3 -m pip install package_name
```

### Requirements

```bash
python3 -m pip install -r requirements.txt
```

### Info

```bash
python3 -m pip list           # show installed packages
python3 -m pip show package   # details on a package
python3 -m pip list --outdated
```

### Why `python3 -m pip`?

- Guarantees you're using the **pip** tied to that **Python interpreter**.
- Prevents mixing packages between system Python (`/usr/bin/python3`) and Homebrew or venv Pythons.
- Works even if `pip`/`pip3` isn't in your `$PATH`.

Always prefer:

```bash
python3 -m pip install ...
```

instead of plain `pip install ...`.

### Pip with Python Virtual Environments (venv)

### Create & Activate venv

```bash
python3 -m venv env_name      # create a new venv in ./env_name
source env_name/bin/activate  # activate (zsh/bash)
deactivate                    # exit the venv
```

> Once activated, `python` and `pip` refer to the venv's interpreter --- no need for `python3 -m pip`.

## Pip Inside venv

```bash
pip install package_name        # install latest
pip install package_name==1.2.3 # install specific version
pip install -r requirements.txt # install from requirements file

pip list        # list installed packages
pip show name   # details on one package
pip freeze > requirements.txt   # export exact versions
```

### Why Use venv?

- Keeps dependencies **isolated per project**.
- Prevents conflicts between global/system packages.
- Lets you use different package versions across projects.

### Rule of Thumb

- **Global installs** → use

  ```bash
  python3 -m pip install ...
  ```

- **Inside venv** → just use

  ```bash
  pip install ...
  ```