在centos 7上安装python netsnmp

时间:2015-04-22 06:09:21

标签: python net-snmp

我收到此错误fatal error: net-snmp/net-snmp-config.h: No such file or directory。我已经安装了gcc, python-devel, net-snmp, net-snmp-utils, net-snmp-python和其他开发依赖项。

CentOS Linux release 7.1.1503 (Core)
[admin@localhost python]$ wget http://sourceforge.net/projects/net-snmp/files/net-snmp/5.5.2/net-snmp-5.5.2.tar.gz
[admin@localhost python]$ pwd
/tmp/net-snmp-5.5.2/python
[admin@localhost python]$ python setup.py build
sh: net-snmp-config: command not found
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/netsnmp
copying netsnmp/__init__.py -> build/lib.linux-x86_64-2.7/netsnmp
copying netsnmp/client.py -> build/lib.linux-x86_64-2.7/netsnmp
creating build/lib.linux-x86_64-2.7/netsnmp/tests
copying netsnmp/tests/__init__.py -> build/lib.linux-x86_64-2.7/netsnmp/tests
copying netsnmp/tests/test.py -> build/lib.linux-x86_64-2.7/netsnmp/tests
running build_ext
building 'netsnmp.client_intf' extension
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/netsnmp
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/admin/miniconda/envs/py_env_clink/include/python2.7 -c netsnmp/client_intf.c -o build/temp.linux-x86_64-2.7/netsnmp/client_intf.o
netsnmp/client_intf.c:9:38: fatal error: net-snmp/net-snmp-config.h: No such file or directory
 #include <net-snmp/net-snmp-config.h>
compilation terminated.
error: command 'gcc' failed with exit status 1
[admin@localhost python]$

UPDATE1:在netsnmp源目录上运行./configure && make && make install后,我就可以运行python setup.py install了。但是,现在我从python中得到了这个错误:

>>> import netsnmp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "netsnmp/__init__.py", line 1, in <module>
    from client import *
  File "netsnmp/client.py", line 1, in <module>
    import client_intf
ImportError: No module named client_intf
>>> 

UPDATE2:我的不好!!我从netsnmp源目录cd /tmp/net-snmp-master/python/的目录运行python解释器,这导致我给出了预期的错误,因为python没有使用从egg中导入,而是来自源。无论如何,在做cd ~之后,我收到了新的错误

>>> import netsnmp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.linux-x86_64/egg/netsnmp/__init__.py", line 1, in <module>
    #
  File "build/bdist.linux-x86_64/egg/netsnmp/client.py", line 1, in <module>
  File "build/bdist.linux-x86_64/egg/netsnmp/client_intf.py", line 7, in <module>
  File "build/bdist.linux-x86_64/egg/netsnmp/client_intf.py", line 6, in __bootstrap__
ImportError: libnetsnmp.so.30: cannot open shared object file: No such file or directory
>>> exit()

UPDATE3

[root@localhost ~]# sudo ldconfig
[root@localhost ~]# sudo ldconfig -p | grep netsnmp
    libnetsnmptrapd.so.31 (libc6,x86-64) => /lib64/libnetsnmptrapd.so.31
    libnetsnmptrapd.so (libc6,x86-64) => /lib64/libnetsnmptrapd.so
    libnetsnmpmibs.so.31 (libc6,x86-64) => /lib64/libnetsnmpmibs.so.31
    libnetsnmpmibs.so (libc6,x86-64) => /lib64/libnetsnmpmibs.so
    libnetsnmphelpers.so.31 (libc6,x86-64) => /lib64/libnetsnmphelpers.so.31
    libnetsnmphelpers.so (libc6,x86-64) => /lib64/libnetsnmphelpers.so
    libnetsnmpagent.so.31 (libc6,x86-64) => /lib64/libnetsnmpagent.so.31
    libnetsnmpagent.so (libc6,x86-64) => /lib64/libnetsnmpagent.so
    libnetsnmp.so.31 (libc6,x86-64) => /lib64/libnetsnmp.so.31
    libnetsnmp.so (libc6,x86-64) => /lib64/libnetsnmp.so
[root@localhost ~]# find / -name libnetsnmp.so*
find: ‘/run/user/1000/gvfs’: Permission denied
/usr/lib64/libnetsnmp.so
/usr/lib64/libnetsnmp.so.31
/usr/lib64/libnetsnmp.so.31.0.2
/usr/local/lib/libnetsnmp.so.30.0.3
/usr/local/lib/libnetsnmp.so.30.0.1
/usr/local/lib/libnetsnmp.so
/usr/local/lib/libnetsnmp.so.30
[root@localhost ~]# 

UPDATE4 :最后通过运行sudo ldconfig并修改/etc/ld.so.conf.d/libc.conf

来解决问题
[root@localhost ~]# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
[root@localhost ~]# cat > /etc/ld.so.conf.d/libc.conf <<EOF
> /usr/local/lib
> EOF
[root@localhost ~]# ldconfig
[root@localhost ~]# python
>>> import netsnmp
>>> exit()
[root@localhost ~]# 

1 个答案:

答案 0 :(得分:2)

确保已安装net-snmp-devel。 检查/usr/include/net-snmp/net-snmp-config.h

的现有内容