I posted this on another thread but messed up the title (called it y2exe) and I want to make sure this gets found if someone can help. I'm using py2exe and pysnmp, and they seem to be incompatible, at least on the oneliner form I'm using. Pysnmp claims to be
py2exe friendly, and I want to know what I'm doing wrong.

Here's the code:

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

def doCmd( key ):    
    errorIndication, errorStatus, errorIndex, varBinds = 
           cmdgen.CommunityData('my-agent', 'public', 0),  
           cmdgen.UdpTransportTarget(("", 161 )),
    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's the output I get when I run this:
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

Here's my compilation script:

from distutils.core import setupimport py2exe setup(console=['snmpbad.py'])from distutils.core import setup
import py2exe


Any help would be extremely appreciated!

Edited by LoveMyPadres: n/a

6 Years
Discussion Span
Last Post by LoveMyPadres

Dident get you pysnmp script to work.
Here is a working py2exe kode.

from distutils.core import setup
import py2exe
import sys

def py_exe(file_in=None):
    if len(sys.argv) == 1:

    setup(options = {'py2exe': {'compressed': 1, 'optimize': 2, 'ascii': 1, 'bundle_files': 3}},
           zipfile = None,

           ## Can use console or window
           ## Filpath to '....py' or same folder as you run this py file from
           console = [{'script': 'your_script.py'}])

You can also try Gui2exe.

Edited by snippsat: n/a


When I run it, I have to type

setup py2exe

Perhaps that would execute it. I'll try yours, it looks much more complete. I'll also check into gui2exe.


When I run it, I have to type

setup py2exe

You run it as every other python code.
From your editor or command line python name_of_script.py


Make sure you are running the latest pysnmp and have the following code in your app's setup.py:

if "py2exe" in sys.argv:
    import py2exe
    # fix executables
    options['console'] = options['scripts']
    del options['scripts']
    # add files not found by modulefinder
    options['options'] = {
        'py2exe': {
            'includes': [

apply(setup, (), options)

Edited by popper12: n/a


AH! The 'includes' was the piece of the puzzle I was missing. I was not able to understand how to incorporate your setup.py fragments into my setup.py. Here is how I modified my setup.py to use the options argument:

from distutils.core import setup
import py2exe

setup( console = [
               { "script": "monitor.py", 
                  "icon_resources": [(0, "monitor.ico")]
       options = { 
                'includes': [                

This worked for me, and now when I run the snmp command that was failing, it works as expected. THANK YOU! THANK YOU!

So I can better understand, could you repost you setup code as a complete program? I have never used the apply() function; it's deprecated, but from what I read I can see the usefulness of it. I could not figure out how to set up the rest of the file such that the apply() did what I wanted, with the rest of the code. I've been writing Python for about 7 months now, and I'm getting pretty comfortable with what I do, but there are so many ways to do things in this language I feel I'll be learning them forever.

Thank you for helping and posting to this thread.


That was a code snippet from the setup.py pysnmp-apps package. You could
download and check it out.

However you do not really need to use the apply() function. In the
pysnmp-apps case, it was used to invoke setup() function and pass it
a [conditionally] pre-filled dictionary of options.

There are other, more modern, ways to do that (e.g. setup(**options) ).


Popper, thanks again for solving my problem. I really appreciate the help and information.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.