2

I am running a Python program on a Windows XP machine. When I run the program, I get the following error:

File "C:\Python27\lib\pysnmp\smi\builder.pyt, line 230, in loadModules...
pysnmp.smi.error.SmiError: MIB file "SNMPv2-MIB.py[co]" not found in search path

The file SNMPv2-MIB.py is currently located in C:\Python27\Lib\pysnmp\smi\mibs. Does anyone know how I can solve this?

quantum
  • 3,672
  • 29
  • 51
Lulu
  • 21
  • 1
  • 1
  • 2
  • @AaronMcSmooth : The solution has been provided here so I guess we can mark the other question as duplicate as the other one is more recent. – pyfunc Sep 17 '10 at 05:25
  • @pyfunc. Already done, I hadn't noticed the other one was more recent. I can't undo my vote but I did vote to close that one as well. If anyone wants to vote on it, it's at:http://stackoverflow.com/questions/3732439/errors-using-pysnmp-on-windows-xp – aaronasterling Sep 17 '10 at 05:27

5 Answers5

6

if a mib is missing make sure you have performed a pip install pysnmp-mibs first if you used pip install pysnmp.

biegleux
  • 13,179
  • 11
  • 45
  • 52
Thomas
  • 69
  • 1
  • 2
3

I just ran into the same issue. I filed a bug for it and included a patch: https://sourceforge.net/tracker/?func=detail&aid=3204704&group_id=14735&atid=114735

As Sivakumar says, the reason it's failing is because pysnmp is looking for MIBs with a .pyc or .pyw extension. pysnmp gets these extensions from imp.get_suffixes(). Based on the way pysnmp deals with the extensions returned from this function, the .pyw entry will overwrite the .py entry. The fix I proposed will simply ignore the .pyw extension.

If you install the library from the .egg it should work fine because the .egg includes compiled (pyc) MIBs.

Joshua
  • 31
  • 1
  • This solved for me.. I was stripping the pyc's around to squeeze on size, but pysnmp didn't like it so restoring it with a simple `python -m compileall ./` diddathing. – Riccardo Manfrin Sep 20 '19 at 11:00
2

You are not able to load the MIB file.

Can you check :

>>> print builder.MibBuilder().getMibPath()

Usually this should be ok as the mib instances should be in

pysnmp/smi/mibs/instances

Code where error is raised in builder.py

if not self.__modSeen.has_key(modName):
    raise error.SmiError(
        'MIB file \"%s\" not found in search path' % (modName and modName + ".py[co]")
            )

Usually this should get solved by calling setMibPath on the mibBuilder instance before calling loadModules.

Since the path you are getting

C:\Python27\lib\pysnmp\smi\mibs\instances, 
C:\Python27\lib\pysnmp\smi\mibs, 
C:\Python27\lib\pysnmp_mibs

Why don't you move the file to one of these directories? The place where it is currently located

  • C:\Python27\Lib\pysnmp\smi\mibs

is not among the paths that you got via builder.MibBuilder().getMibPath()

pyfunc
  • 65,343
  • 15
  • 148
  • 136
  • C:\Python27\lib\pysnmp\smi\mibs\instances, C:\Python27\lib\pysnmp\smi\mibs, C:\Python27\lib\pysnmp_mibs – Lulu Sep 16 '10 at 21:48
  • why is it looking for "SNMPv2-MIB.py[co]" instead of SNMPv2-MIB.py? – Lulu Sep 16 '10 at 21:49
1

I ran into the same issue (with pysnmp-4.2.5). I generated my own MIB python file using:

build-pysnmp-mib -o IF-MIB.py /usr/share/mibs/ietf/IF-MIB

on RHEL6 (build-pysnmp-mib does not work on RHEL5 as it requires libsmi version > 0.4.5 and RHEL5 just has this version while RHEL6 has 0.4.8).

Then I copied the generated file IF-MIB.py into the directory where the other python MIB files of pysnmp are located, (/.../site-packages/pysnmp/smi/mibs/)

Andre Holzner
  • 18,333
  • 6
  • 54
  • 63
0

Today i too face this same issue. The mibs path is correctly set. While running the pysnmp in debugging mode, i am able to found that it is expecting a SNMPv2-MIB.pyc or .pyw file.

Since i have unzipped the pysnmp from source and using it, the corresponding pyc file for the mib module is not available in that folder structure. I havent tried compiling the corresponding .py files available in the pysnmp-4.1.13a\pysnmp\smi\mibs\instances or pysnmp-4.1.13a\pysnmp\smi\mibs, instead i used the easyinstall script to download the pysnmp module.

With the egg file, now the issue is not coming.

Thanks Sivakumar

Siva
  • 59
  • 2
  • 8