I’m trying to run up a VM on Azure using CLI commands on my Ubuntu 20.04 (Focal) workstation. I’m following the
official instructions
. On running the az vm create
command, I get the following error:
The command failed with an unexpected error. Here is the traceback:
No module named 'antlr4'
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/knack/cli.py", line 206, in invoke
cmd_result = self.invocation.execute(args)
File "/usr/lib/python3/dist-packages/azure/cli/core/commands/__init__.py", line 528, in execute
self.commands_loader.load_arguments(command)
File "/usr/lib/python3/dist-packages/azure/cli/core/__init__.py", line 300, in load_arguments
loader.load_arguments(command) # this adds entries to the argument registries
File "/usr/lib/python3/dist-packages/azure/cli/command_modules/vm/__init__.py", line 31, in load_arguments
from azure.cli.command_modules.vm._params import load_arguments
File "/usr/lib/python3/dist-packages/azure/cli/command_modules/vm/_params.py", line 31, in <module>
from azure.cli.command_modules.monitor.actions import get_period_type
File "/usr/lib/python3/dist-packages/azure/cli/command_modules/monitor/actions.py", line 7, in <module>
import antlr4
ModuleNotFoundError: No module named 'antlr4'
Looks like the Azure CLI packages for Ubuntu have a dependency on ‘antlr4’ python library, and that isn’t being packaged or distributed upstream for whatever reason. In my case I’m using the Ubuntu Focal (20.04) series.
After much hunting for ‘proper’ packages, it turned out the simple solution was just to…
sudo pip3 install antlr4-python3-runtime
That’s all folks!