As the title says, when I tried to run the Python SDK of Azure, the following message appeared and I was addicted to it, so make a note of the corresponding content
ModuleNotFoundError: No module named 'azure'
Conducted up to the construction of the virtual environment of the tutorial Starting cloud development using Azure library for Python
Then run this program Operating Azure from Python with Azure Management Library
It is still a reference site, but for the time being
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.resource import ResourceManagementClient
import Config
# (1) Access information
SUBSCRIPTION_ID = Config.SUBSCRIPTION_ID
TENANT_ID = Config.TENANT_ID
CLIENT_ID = Config.CLIENT_ID
CLIENT_SECRET= Config.CLIENT_SECRET
def main():
# (2) Obtaining credentials
creds = ServicePrincipalCredentials(
client_id = CLIENT_ID,
secret = CLIENT_SECRET,
tenant = TENANT_ID)
# (3) Get the object that operates the resource group by specifying the subscription ID
client = ResourceManagementClient(creds, SUBSCRIPTION_ID)
# (4) Get the resource group list
for rg in client.resource_groups.list():
print("{} {}".format(rg.name, rg.location))
if __name__ == '__main__':
main()
I'm not convinced, but now it works. *Execution result
fabric2 eastus
MC_fabric2_sample-HLF-AKS_eastus eastus
NetworkWatcherRG japaneast
MC_fabric_sample-HLF-AKS_westus westus
baasTest japanwest
baasTest2 japanwest
blockchain japanwest
fabric japanwest
fabric3 japanwest
cloud-shell-storage-southeastasia southeastasia
Recommended Posts