2015-10-26 46 views
0

我使用python 2.7.8。
我这个代码转换成一个EXE使用py2exe:py2exe不能与pysnmp 4.3.0一起使用

from pysnmp.hlapi.asyncore import * 
def cbFun(snmpEngine, sendRequestHandle, errorIndication, errorStatus, errorIndex, varBinds, cbCtx): 
    print(errorIndication, errorStatus, errorIndex, varBinds) 
snmpEngine = SnmpEngine() 
getCmd(snmpEngine, 
     CommunityData('public'), 
     UdpTransportTarget(('demo.snmplabs.com', 161)), 
     ContextData(), 
     ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), 
     cbFun=cbFun) 
snmpEngine.transportDispatcher.runDispatcher() 

但每次我运行exe我碰到下面的错误时间:

could not get source code 
Traceback (most recent call last): 
File "Maprinter.py", line 11, in <module> 
File "pysnmp\entity\rfc3413\oneliner\cmdgen.pyc", line 124, in nextCmd 
File "pysnmp\hlapi\asyncore\cmdgen.pyc", line 337, in nextCmd 
File "pysnmp\hlapi\varbinds.pyc", line 30, in makeVarBinds 
File "pysnmp\smi\rfc1902.pyc", line 707, in resolveWithMib 
File "pysnmp\smi\rfc1902.pyc", line 302, in resolveWithMib 
File "pysnmp\smi\compiler.pyc", line 42, in addMibCompiler 
File "pysmi\parser\smi.pyc", line 21, in __init__ 
File "pysmi\lexer\smi.pyc", line 83, in __init__ 
File "pysmi\lexer\smi.pyc", line 100, in reset 
File "ply\lex.pyc", line 906, in lex 
File "ply\lex.pyc", line 580, in validate_all 
File "ply\lex.pyc", line 822, in validate_rules 
File "ply\lex.pyc", line 833, in validate_module 
File "inspect.pyc", line 690, in getsourcelines 
File "inspect.pyc", line 538, in findsource 
IOError: could not get source code 

我应该怎么做得太解决这个问题呢?

回答

0

这可能与“检查”模块行为有关,而不是pysnmp。有类似问题的ticket。虽然它被拒绝了。

考虑一旦开始导入东西时尝试不更改当前工作目录,则相对路径可能会继续工作。

此问题可能不会在Python 2.6-和3.4+中显示。