Python OSX - /usr/local/lib/python2.7/site-packages/easysnmp/interface.so中的平面命名空间

时间:2017-04-04 07:00:38

标签: python macos

我在这篇文章中可以看到类似的问题https://github.com/fgimian/easysnmp/issues/42 但我不确定同样的问题是否适用于我。

基本上我已经通过home-brew安装了python

alexs-mbp:~ alex$ which python
/usr/local/bin/python
alexs-mbp:~ alex$

并通过pip和net-snmp通过home-brew安装easysnmp

alexs-mbp:~alex$ python
Python 2.7.13 (default, Dec 18 2016, 07:03:39) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import easysnmp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/easysnmp/__init__.py", line 1, in <module>
    from .easy import (  # noqa
  File "/usr/local/lib/python2.7/site-packages/easysnmp/easy.py", line 3, in <module>
    from .session import Session
  File "/usr/local/lib/python2.7/site-packages/easysnmp/session.py", line 8, in <module>
    from . import interface
ImportError: dlopen(/usr/local/lib/python2.7/site-packages/easysnmp/interface.so, 2): Symbol not found: _netsnmp_transport_config_compare
  Referenced from: /usr/local/lib/python2.7/site-packages/easysnmp/interface.so
  Expected in: flat namespace
 in /usr/local/lib/python2.7/site-packages/easysnmp/interface.so

使用brew检查时,我也收到此消息

 Warning: net-snmp is a keg-only and another version is linked to opt.
Use `brew install --force` if you want to install this version
alexs-mbp:~ alex$ brew install net-snmp --force
Warning: net-snmp-5.7.3 already installed, it's just not linked.
alexs-mbp:~ alex$ 

我做了一个brew链接,它给了我以下

Warning: net-snmp is a keg-only and another version is linked to opt.
Use `brew install --force` if you want to install this version
alexs-mbp:~ alex$ brew install net-snmp --force
Warning: net-snmp-5.7.3 already installed, it's just not linked.
alexs-mbp:~ alex$ brew link net-snmp
Warning: net-snmp is keg-only and must be linked with --force
Note that doing so can interfere with building software.

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/usr/local/opt/net-snmp/bin:$PATH"' >> ~/.bash_profile
  echo 'export PATH="/usr/local/opt/net-snmp/sbin:$PATH"' >> ~/.bash_profile
alexs-mbp:~ alexwilloughby$ brew link net-snmp --force
Linking /usr/local/Cellar/net-snmp/5.7.3... 182 symlinks created

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/usr/local/opt/net-snmp/bin:$PATH"' >> ~/.bash_profile
  echo 'export PATH="/usr/local/opt/net-snmp/sbin:$PATH"' >> ~/.bash_profile
alexs-mbp:~ alex$ 

启动python并导入easysnmp仍然给我同样的错误 有谁知道如何解决这个问题?

由于

1 个答案:

答案 0 :(得分:0)

问题似乎源于net-snmp的自制安装与easysnmp的pip安装的不兼容性。尝试卸载easysnmp并从此fork https://github.com/kamakazikamikaze/easysnmp重新安装:

pip uninstall easysnmp
pip install git+https://github.com/kamakazikamikaze/easysnmp.git