You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pyinstaller打包puresnmp代码为exe后出现插件缺失错误求助

Pyinstaller打包puresnmp代码为exe后出现插件缺失错误

问题详情

我用puresnmp通过SNMPv1协议从代理获取数据,代码在PyCharm里运行完全正常,但用Pyinstaller打包成exe后,启动时抛出错误:

Namespace 'puresnmp_plugins.mpm' did not contain a plugin with identifier 0. Known identifiers: []. See the 'puresnmp' documentation on plugins。

已经安装了typing-extensions包,但问题依旧没解决。

代码示例

from puresnmp import Client, ObjectIdentifier as oid, credentials
oids = [oid('.1.3.6.1.2.1.33.1.3.3.1.3.1'),  # upsInputVoltage
        oid('.1.3.6.1.2.1.33.1.3.3.1.2.1'),  # input frequency.
        oid('.1.3.6.1.2.1.33.1.2.5.0'),  # battery voltage.
        oid('.1.3.6.1.2.1.33.1.2.7.0'),  # UPS Battery temperature
        oid('.1.3.6.1.2.1.33.1.2.4.0'),  # Battery capacity
        oid('.1.3.6.1.2.1.33.1.4.4.1.2.1'),  # upsOutputVoltage
        oid('.1.3.6.1.2.1.33.1.4.2.0'),  # output frequency
        oid('.1.3.6.1.2.1.33.1.4.4.1.5.1')  # ups load percentage
        ]
client = Client('172.16.2.101', credentials.V1("public"), port=161)
result1 = client.multiget(oids)
x = run(result1)
result = [0] * len(oids)
for j in range(len(oids)):
    xx = bytes(x[j])
result[j] = int.from_bytes(xx[2:], byteorder="big", signed=True)

解决方法

这个问题是Pyinstaller打包时没正确收集puresnmp的插件导致的,puresnmp靠插件系统处理MPM(消息处理模型),SNMPv1对应的插件是puresnmp_plugins.mpm.v1,打包时需要手动指定导入这个插件。

方法1:直接用命令行参数打包

打包时添加--hidden-import参数:

pyinstaller --hidden-import=puresnmp_plugins.mpm.v1 your_script.py

方法2:通过spec文件配置打包

  1. 先生成spec文件:
pyinstaller --name your_app your_script.py
  1. 打开生成的your_app.spec,在hiddenimports列表里添加插件路径:
hiddenimports=['puresnmp_plugins.mpm.v1'],
  1. 用spec文件重新打包:
pyinstaller your_app.spec

补充

如果还有其他插件报错,可以把SNMPv1需要的安全插件也加上,命令改成:

pyinstaller --hidden-import=puresnmp_plugins.mpm.v1 --hidden-import=puresnmp_plugins.security.v1 your_script.py

内容的提问来源于stack exchange,提问作者Venaktesh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 01:26:20