Hi

I'm using pysnmp 4.1.1.4a (yes, I know there's a newer version but it has the same behavior) and py2exe. When I execute a pysnmp oneliner, like this:

errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().nextCmd(
    cmdgen.CommunityData('my-agent', 'public', 0),
    cmdgen.UdpTransportTarget((self.IPaddress, self.Port)),
    self.keydict[ key ][0]

I get this output:

File "pysnmp\entity\rfc3413\oneliner\cmdgen.pyc", line 116, in __init__
  File "pysnmp\entity\engine.pyc", line 16, in __init__
  File "pysnmp\proto\rfc3412.pyc", line 16, in __init__
  File "pysnmp\smi\builder.pyc", line 143, in __init__
  File "pysnmp\smi\builder.pyc", line 35, in init
  File "pysnmp\smi\builder.pyc", line 80, in _init
ImportError: No module named mibs.instances

Pysnmp clains to be py2exe friendly. Anyone got a solution for this? When I compiled the application, I did not specify any extra options. My program already uses telnet, serial and other packages successfully. I know that pysnmp did some tricks in code that may have fooled py2exe, but is there a workaround?

Thanks

Kelly

Can you post the script,so shall i test it in py2exe and cxfreeze.

Of course, the title should be "py2exe", that's the only thing I couldn't edit :-)

Here is the full code:

from pysnmp.entity.rfc3413.oneliner import cmdgen
from pysnmp.entity import config
from Tkinter import *

def doCmd( key ):
    errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().getCmd(
        cmdgen.CommunityData('my-agent', 'public', 0),
        cmdgen.UdpTransportTarget(("127.0.0.1", 161)),                                  
        key
    )
    print errorIndication
    print errorStatus
    for item in varBinds:
        print item

doCmd( (1,3,6,1,4,1,557,1,1,10,3,1,1,305) )

Here is my compilation script:

from distutils.core import setup
import py2exe

setup(console=['snmpbad.py'])

Produces this output:
Traceback (most recent call last):
File "snmpbad.py", line 16, in <module>
File "snmpbad.py", line 6, in doCmd
File "pysnmp\entity\rfc3413\oneliner\cmdgen.pyc", line 116, in __init__
File "pysnmp\entity\engine.pyc", line 16, in __init__
File "pysnmp\proto\rfc3412.pyc", line 16, in __init__
File "pysnmp\smi\builder.pyc", line 143, in __init__
File "pysnmp\smi\builder.pyc", line 35, in init
File "pysnmp\smi\builder.pyc", line 80, in _init
ImportError: No module named mibs.instances

Thanks for any assistance.

Kelly

Try something like this:

from distutils.core import setup
import sys

if "py2exe" in sys.argv:
    import py2exe
    # fix executables
    options['console'] = ['snmpbad.py']
    del options['scripts']
    # add files not found my modulefinder
    options['options'] = {
        'py2exe': {
            'includes': [
                'pysnmp.smi.mibs.*',
                'pysnmp.smi.mibs.instances.*'
                ]
            }
        }

apply(setup, (), options)

I had to make some changes to your setup code to compile. Here is what I used:

from distutils.core import setup
import sys
options = {}

if "py2exe" in sys.argv:
    import py2exe
    # fix executables
    options['console'] = ['snmpbad.py']
    #del options['scripts']
    # add files not found my modulefinder
    options['options'] = {
        'py2exe': {
            'includes': [
                'pysnmp.smi.mibs.*',
                'pysnmp.smi.mibs.instances.*'
                ]
            }
        }

apply(setup, (), options)

This worked, and the code now works as expected. The Internet is a beautiful thing. Thank you so much for solving my problem. I will make sure to pay it forward by helping someone else.

Cheers!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.