How do I fix "No module named 'easysnmp'"

when I try to run the code. I am getting an error.

The error is

    Traceback (most recent call last):
       File "A2.py", line 2, in <module>
         from easysnmp import Session
     ImportError: No module named 'easysnmp'

Note: I am getting the above error.Even though, I have installed easysnmp module.

The code is

 #!/usr/bin/python
from easysnmp import Session
import argparse
import time
parser = argparse.ArgumentParser(description='probe')
parser.add_argument('cred',help='credentials')
parser.add_argument('freq',type=float,help='enter frequency')
parser.add_argument('samples',type=int,help='enter samples')
parser.add_argument('oid',nargs='+',help='enter oid')
args=parser.parse_args()
t=1/args.freq
s=args.samples
cred1=args.cred
ip,port,comm=cred1.split(":")
count=0
session=Session(hostname=ip,remote_port=port,community=comm, version=2,timeout=2,retries=1)
args.oid.insert(0, '1.3.6.1.2.1.1.3.0')
old=[]
out1=[]
t4=0
while (count!=s):
  t1=time.time()
  new = session.get(args.oid)
  t2=time.time()
  if len(new)==len(old):
   newtime=float(new[0].value)/100
   oldtime=float(old[0].value)/100
   if args.freq > 1:
     tdiff = newtime-oldtime
   if args.freq <= 1:
     tdiff1 = t1-t4
     if tdiff!=0:
      tdiff = int(tdiff1)
     else:
      tdiff = int(t)
   for i in range(1,len(args.oid)):
      if new[i].value!="NOSUCHINSTANCE" and old[i].value!="NOSUCHINSTANCE":
         a=int(new[i].value)
         b=int(old[i].value)
         if a>=b:
           out=(a-b)/tdiff
           out1.append(out)
         if a<b and new[i].snmp_type=="COUNTER64":
           out=((2**64+a)-b)/tdiff
           out1.append(out)
         if a<b and new[i].snmp_type=="COUNTER32":
           out=((2**32+a)-b)/tdiff
           out1.append(out)
      else:
        print t1, "|"
   count=count+1
   if len(out1)!=0:
      sar = [str(get) for get in out1]
      print int(t1) ,'|', ("|" . join(sar))
  old = new[:]
  t4=t1
  del out1[:]
  t3=time.time()
  if t-t3+t1>0:
    time.sleep(t-t3+t1)
  else:
    time.sleep(0.0)

Upvotes: 0

Views: 2450

Answers (2)

S. Pellegrino
S. Pellegrino

Reputation: 638

My wild guess is that you installed the module for python 3 and used python 2 or the other way around.

Try

pip install easysnmp

or

pip3 install easysnmp

Upvotes: 0

Rozakos
Rozakos

Reputation: 618

Try to put import easysnmp at the top of your code, it solved the problem for me at a similar situation!

Upvotes: 2

Related Questions