1
votes

I am using a python code to import azure activity log, but its giving module error below is the error

 from azure.monitor import MonitorClient

File "/home/seceon/azure.py", line 1, in from azure.monitor import MonitorClient ImportError: No module named monitor

I need help to remove this import error.

3
do you install the package "azure-monitor"? - Ivan Yang
yes did but the same error. - Ajay Gupta

3 Answers

2
votes

Looks like you have named your script as azure.py This is conflicting with the installed azure-monitor module. I recommend you rename your script to something else and try running it again. It should start working.

1
votes

It's a package azure-monitor you used for the Azure Service Management in the older version of Azure SDK for Python which GitHub repo tag is azure-monitor_0.3.1. You can see it at https://pypi.org/project/azure-monitor/.

For installing it, I create a virtual environment in my current Python 3.6.7. Here is my steps.

  1. Command virtualenv azure-monitor-test and cd azure-monitor-test
  2. Command source bin/activate
  3. Command pip install azure-monitor
  4. Run from azure.monitor import MonitorClient sucessfully in my Python interpreter, as the figure below.

enter image description here

  1. Check my installed pip packages via command pip list | grep azure, then you will see these version of its related packages, as below.

enter image description here

1
votes

This package is deprecated and has been replaced by azure-mgmt-monitor: https://pypi.org/project/azure-mgmt-monitor/

https://docs.microsoft.com/python/api/overview/azure/monitoring

But yes, I agree with the inital answer that calling your script "azure.py" is a bad idea :)

(I work at MS in the team that releases these Azure packages for Python)