Craig Forrester

The Pleasure of Finding Things Out

github linkedin email rss
Install Azure CLI on Windows 10 using Python pip
February 19, 2018
6 minutes read

TL;DR

If you want to cut to the chase, here’s the complete list of commands:

# Download the Python 3.6.4 installer with PowerShell
Invoke-WebRequest -Uri 'https://www.python.org/ftp/python/3.6.4/python-3.6.4-amd64.exe' -OutFile '.\python-3.6.4-amd64.exe'

# Passive Install of Python for All Users
# Run this from an elevated PowerShell prompt
.\python-3.6.4-amd64.exe /passive TargetDir="C:\Python" InstallAllUsers=1 PrependPath=1

Run these in a new PowerShell window after installing Python:

# Install Azure CLI system-wide
pip install azure-cli

# Upgrade Azure CLI later on
pip install --upgrade azure-cli

For a fuller explanation, read on…

Why Azure CLI?

If you manage anything in Azure for any length of time, you will most-likely find yourself wanting to get faster and more efficient at it, which means you’re going to want to use command line tools and scripting. One of the best tools you have at your disposal is free, directly from Microsoft: Azure CLI.

If you’re mostly familiar with Windows, you may ask: “Why not use Azure PowerShell instead?” I would argue that it doesn’t have to be an either/or proposition — we can make use of Azure PowerShell modules and Azure CLI both, for differing, similiar, or even overlapping uses. I’ll give you a few reasons why you may want to consider having both in your toolbox…

One reason for using Azure CLI is simply laziness. It takes a great deal more typing to perform even simple actions using PowerShell than the Azure CLI. This alone can provide enough of a productivity boost to make any effort worth it. Yes, PowerShell gives us the ability to craft custom aliases, but there are hundreds of Azure cmdlets and doing so would be a waste of time when Azure CLI is already available. Azure CLI already has a beautifully organized command hierarchy that is perfect for interactive use. This leads us to our second reason…

Azure CLI commands are easier to recall and build on when you’re typing interactively; far more than PowerShell, in my opinion.

Installing Azure CLI on Windows

If you’re using Windows, you may be tempted to follow the documentation and use the Windows installer to install Azure CLI. Azure CLI 2 is written in Python, and so I suggest installing it with Python instead. There are a couple of reasons for this.

For one, because having Python installed on your system has numerous other benefits besides, not the least of which is that you can use it directly for scripting, building applications, or installing other tools.

Another benefit is that Python comes with its own package management tool called pip for installing and managing Python modules. Think: Apt, or Homebrew, or NuGet, but for Python. And if you know any of these tools already, then you probably don’t need much convincing that having a package manager is a good idea. If you’re not familiar with package managers, then it should suffice to say that they make installing, upgrading, removing, and maintaining software much easier — no more searching for installers, downloading, saving, installing, and repeating the entire process when a new version is released.

Install Python

You will need Python 3 to get started, so go download that first.

# Download the Python 3.6.4 installer with PowerShell
Invoke-WebRequest -Uri 'https://www.python.org/ftp/python/3.6.4/python-3.6.4-amd64.exe' -OutFile '.\python-3.6.4-amd64.exe'

Once it’s downloaded, go ahead install it, system-wide:

# Run this from an elevated PowerShell prompt
.\python-3.6.4-amd64.exe /passive TargetDir="C:\Python" InstallAllUsers=1 PrependPath=1 Include_test=0

This will install Python 3 to C:\Python, available for all users, add install and Scripts directories to your PATH environment variable, and the .py file extension to your PATHEXT environment variable, for easy launching of scripts.

If you do not want to install it system-wide, or are not able to for lack of rights on your system, you can simply remove InstallAllUsers=1. See the Using Python on Windows in the Python documentation for more details.

Once installed, you should be able to open a new PowerShell window and run the following two commands successfully:

PS> python --version
Python 3.6.4

PS> pip --version
pip 9.0.1 from c:\python\lib\site-packages (python 3.6)

Install Azure CLI using pip

Now that Python and pip are installed, install Azure CLI is as easy as running this single command:

# Install Azure CLI system-wide
pip install azure-cli

If you did not do a system-wide installation, but performed user install instead, then run pip install with the --user switch:

# Install Azure CLI for the Current User
pip install --user azure-cli

Upgrading Azure CLI using pip

To upgrade Azure CLI later on, simply run pip install with the the --upgrade switch:

# Upgrade Azure CLI
pip install --upgrade azure-cli

Or, for user installs:

# Upgrade Azure CLI
pip install --upgrade --user azure-cli

Once complete, you should see Successfully installed... followed by all the packages upgraded.

Verifying the Installation

Now, to verify the installation, simply open a Command Prompt or PowerShell window and check that the az command works and the version installed:

PS> az --version
azure-cli (2.0.27)

acr (2.0.21)
acs (2.0.26)
advisor (0.1.2)
appservice (0.1.26)
backup (1.0.6)
batch (3.1.10)
batchai (0.1.5)
billing (0.1.7)
cdn (0.0.13)
cloud (2.0.12)
cognitiveservices (0.1.10)
command-modules-nspkg (2.0.1)
configure (2.0.14)
consumption (0.2.1)
container (0.1.18)
core (2.0.27)
cosmosdb (0.1.19)
dla (0.0.18)
dls (0.0.19)
eventgrid (0.1.10)
extension (0.0.9)
feedback (2.1.0)
find (0.2.8)
interactive (0.3.16)
iot (0.1.17)
keyvault (2.0.18)
lab (0.0.17)
monitor (0.1.2)
network (2.0.23)
nspkg (3.0.1)
profile (2.0.19)
rdbms (0.0.12)
redis (0.2.11)
reservations (0.1.1)
resource (2.0.23)
role (2.0.19)
servicefabric (0.0.10)
sql (2.0.21)
storage (2.0.25)
vm (2.0.26)

Python location 'C:\Python\python.exe'
Extensions directory 'C:\Users\user\.azure\cliextensions'

Python (Windows) 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)]

Legal docs and information: aka.ms/AzureCliLegal

If you see output like this, then congratulations, you’ve gotten the CLI to install and run correctly!

Hopefully you found this an easy way to get Azure CLI installed. In future posts, I’ll go over using Azure CLI interactively on Windows. If you’re anxious to get started, type az help for a summary of commands, and az login to start the login process.

Listing Available Versions

One last note: You may at some point find yourself wondering what the latest version of the azure-cli package is. As is often the case, the same question appears on Stack Overflow and can be summarized: “Run the install command and put == at the end of the package name, but omit the version number.” Like this:

pip install azure-cli==

Example Output:

Collecting azure-cli==
  Could not find a version that satisfies the requirement azure-cli==
  (from versions: 0.1.0b4, 0.1.0b7, 0.1.0b8, 0.1.0b9, 0.1.0b10, 0.1.0b11,
  0.1.1b1, 0.1.1b2, 0.1.1b3, 0.1.2rc1, 0.1.2rc2, 2.0.0, 2.0.1, 2.0.2, 2.0.3,
  2.0.4, 2.0.5, 2.0.6, 2.0.7, 2.0.8, 2.0.9, 2.0.10, 2.0.12, 2.0.13, 2.0.14, 
  2.0.15, 2.0.16, 2.0.17, 2.0.18, 2.0.19, 2.0.20, 2.0.21, 2.0.22, 2.0.23, 
  2.0.24, 2.0.25, 2.0.26, 2.0.27, 2.0.28, 2.0.29, 2.0.30, 2.0.31, 2.0.32, 
  2.0.33, 2.0.34, 2.0.35, 2.0.37, 2.0.38, 2.0.40, 2.0.41, 2.0.42)
  No matching distribution found for azure-cli==

The lastest version is the last in the list. :)

Change Log

  • 2018-07-26 - Added section “Listing Available Versions”
  • 2018-08-10 - Removed option Include_test=0 from Python install

Additional Reading


Back to posts