首页 > 编程语言 > 详细

centos7 安装 Python netsnmp模块

时间:2017-02-07 19:23:39      阅读:968      评论:0      收藏:0      [点我收藏+]

由于模块的安装过程中有点艰难(其实挺简单,只是参照网上的教程很多都装不成功,花了很多时间。。。),所以记下来备忘。

先装一下python-devel 模块,执行命令 yum install python-devel  ,不然在make netsnmp 的过程中会出现如下错误:

netsnmp/client_intf.c:1:20: fatal error: Python.h: No such file or directory
#include <Python.h>
^
compilation terminated.
error: command ‘gcc‘ failed with exit status 1
make: *** [pythonmodules] Error 1

技术分享

下载setuptools-0.6c11-py2.7.egg:https://pypi.python.org/pypi/setuptools/0.6c11#downloads
下载net-snmp-5.7.3.tar.gz:http://www.net-snmp.org/download.html

1) 安装setuptools

1.   chmod +x setuptools-0.6c11-py2.7.egg
2.   ./setuptools-0.6c11-py2.7.egg


2)安装net-snmp

1.   tar -zxvf net-snmp-5.7.3.tar.gz
2.   cd net-snmp-5.7.3
3.   ./configure --with-python-modules
如果想指定安装目录,则需要使用--prefix参数,如:
./configure --prefix=/usr/local/netsnmp --with-python-modules
命令敲完回车,生成makefile过程中,会让用户填写相关信息,其中第一个参数:
Default version of SNMP to use (3): 2
注:此处默认SNMP版本填2,不要填2c,因为2就代表2c,如果输入2c,后期编译会报错。(如果直接按回车,不填写任何数字,后面编译也会报错。后面makefile过程中的提示用户填写的参数,如果不想指定,直接按回车即可。)
4.   make (时间很长)
5.   make install
完成安装之后,就可以试用snmpwalk等工具了。但python中仍无法导入netsnmp模块。下面继续:
3)安装python netsnmp模块
上面的netsnmp安装时未手动指定目录,所以默认安装在/usr/local下了。对应的库文件在/usr/local/lib目录下。
在安装python netsnmp模块时,因模块安装需要,需先增加库文件路径,否则会报错,提示找不到模块: ImportError: libnetsnmp.so.30: cannot open shared object file: No such file or directory
1.   echo "/usr/local/lib" >> /etc/ld.so.conf
2.   ldconfig
3.   cd python
4.   python setup.py build
5.   python setup.py test
出现如下图所示则说明编译测试成功:

技术分享

服务器版Linux最后可能会出现如下图所示的编码问题,可以忽略:

技术分享

6.   python setup.py install
4)测试导入python netsnmp模块

技术分享

 

centos7 安装 Python netsnmp模块

原文:http://www.cnblogs.com/homeways/p/6375394.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!