home

Install Azure CLI with pip

2024-05-22

The MacOS installation of the Azure CLI (brew install azure-cli) likes to install python@3.11 which I personally do not mind, but I do. So, I decided to check the Linux (any) reference for installation, and that failed spectacularly due to a few missing packages, not able to install a specific version of virtualenv, and whatnot.

So, from bits of the official installation script [2], here’s how to setup an installation outside of homebrew. This should work with Linux as well.

installation

INSTALLATION_DIR="..."
cd $INSTALLATION_DIR

python3 -m venv .venv
source .venv/bin/activate # or .venv/bin/activate.fish (depending on your $SHELL)

pip3 install setuptools
pip3 install azure-cli --upgrade

“binary”

Somewhere on your $PATH, plonk an az file, with the following contents,

#!/usr/bin/env bash

# eh
INSTALLATION_DIR="..."

"$INSTALLATION_DIR"/.venv/bin/python3 -m azure.cli "$@"

autocompletions

autocompletions with fish (not that this helps a lot, idk)

# ~/.config/fish/config.fish
# for this though, you need to
# pip3 install argcomplete --break-system-packages

if command -v az > /dev/null;
    eval "$(register-python-argcomplete --shell fish az)"
end

home