1

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.

mloskot
  • 37,086
  • 11
  • 109
  • 136
Ajay Gupta
  • 127
  • 3
  • 13
  • do you install the package "azure-monitor"? – Ivan Glasenberg Mar 11 '19 at 08:30
  • yes did but the same error. – Ajay Gupta Mar 11 '19 at 10:52
  • Possible duplicate of [Importing installed package from script raises "AttributeError: module has no attribute" or "ImportError: cannot import name"](https://stackoverflow.com/questions/36250353/importing-installed-package-from-script-raises-attributeerror-module-has-no-at) – pppery Aug 19 '19 at 13:46

3 Answers3

2

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

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

Peter Pan
  • 23,476
  • 4
  • 25
  • 43
  • I did the same its worked but unfortunately worked only once. After that same module error. – Ajay Gupta Mar 11 '19 at 13:41
  • My bad same module name. Thats why. – Ajay Gupta Mar 11 '19 at 14:01
  • @AjayGupta Due to Python follow the order of `sys.path` to load modules and `.` always at the head of `sys.path`, so a name conflict custom module will override a real module what you want to use. – Peter Pan Mar 20 '19 at 02:55
1

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

https://learn.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)

Laurent Mazuel
  • 3,422
  • 13
  • 27