我最近在Ubuntu上安装了PySNMP库。
http://pysnmp.sourceforge.net/quick-start.html
我遵循了快速启动过程中的“获取SNMP变量”,如上面的链接所解释的那样。
不幸的是,我一直收到这个错误:
File "/home/Camille/Desktop/quick_start.py", line 4, in <module>
getCmd(SnmpEngine(),
NameError: name 'getCmd' is not defined
getCmd()是一个函数,它确实存在
发布于 2016-02-21 20:02:43
这可能是apt包中的打包错误。
在薄荷17.3 (Ubuntu14.04)上,如果我创建一个虚拟环境并使用pip安装PySNMP,我将得到4.3.2版,这很好:
>>> from pysnmp.hlapi import *
>>> getCmd
<function getCmd at 0x7f24e6fab0c8>
但是,如果我通过apt-get install python-pysnmp4
安装ubuntu包,我将得到4.2.5,而上面的代码根本无法工作。(ImportError: No module named hlapi
)
在我的例子中,apt包版本不包括hlapi
模块。
PySNMP 4.2.5源代码的文件清单如下:tag
apt包的文件清单如下:http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/python-pysnmp4/trusty/files/head:/pysnmp/
我不知道它为什么会丢失,但这要么是一个遗漏(他们忘记了hlapi文件夹),要么是其他一些我不清楚的原因。
虽然这与您的错误不一样,但它确实表明可能存在其他打包问题。也许您使用的版本在某种程度上也是不完整的。
总之,如果您创建一个虚拟环境并使用pip
安装PySNMP,您可能会没事。您还可能需要向launchpad维护程序提交一个bug。
发布于 2016-03-22 10:41:36
安装pysnmp时:
$ pip install pysnmp
或
$ easy_install pysnmp
库pysnmp安装在此路径中:
/usr/local/lib/python2.7/dist-packages/
这不是默认路径搜索之一。
在您的程序中添加以下行:
import sys
sys.path.insert(1, '/usr/local/lib/python2.7/dist-packages')
https://stackoverflow.com/questions/35540577
复制相似问题