0

On MacOS, how to use netsnmp in python3?

I have already install python3-netsmp, but import still gets an error.

pip3 install python3-netsnmp

% pip3 list
Package         Version
--------------- -------
altgraph        0.17.2
bcrypt          4.0.1
cffi            1.15.1
cryptography    40.0.2
future          0.18.2
macholib        1.15.2
paramiko        3.1.0
pip             23.1.2
pycparser       2.21
PyNaCl          1.5.0
python3-netsnmp 1.1a1
setuptools      58.0.4
six             1.15.0
wheel           0.37.0

% python3
Python 3.9.6 (default, Mar 10 2023, 20:16:38) 
[Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import netsnmp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jus*/Library/Python/3.9/lib/python/site-packages/netsnmp/__init__.py", line 1, in <module>
    from .client import *
  File "/Users/jus*/Library/Python/3.9/lib/python/site-packages/netsnmp/client.py", line 5, in <module>
    from netsnmp import client_intf
ImportError: dlopen(/Users/jus*/Library/Python/3.9/lib/python/site-packages/netsnmp/client_intf.cpython-39-darwin.so, 0x0002): symbol not found in flat namespace '_netsnmp_transport_config_compare'


Any suggestions? Thanks!

I did some research and some threads mentioned the setup steps on Ubuntu OS. To use netsnmp, the user should install python-dev, libsnmp-dev, snmp-mibs-downloader in advance. I check it on an Ubuntu VM and it works.

The problem is how to install these packages on Mac OS. I cannot find the packages of libsnmp-dev & snmp-mibs-downloader on Mac OS.

sudo apt-get install gcc python-dev
sudo apt-get install libsnmp-dev snmp-mibs-downloader
JustinWuB
  • 1
  • 3
  • You can use homebrew or macports. I usually prefer macports for this. – Shiv May 24 '23 at 03:51
  • @Shiv I tried homebrew, but seems like there's no package on Mac OS. – JustinWuB May 24 '23 at 06:26
  • Did you google the error message? Some possible workarounds in https://stackoverflow.com/questions/35006614/what-does-symbol-not-found-expected-in-flat-namespace-actually-mean – tripleee May 24 '23 at 07:21
  • Are you open to alternative libraries? https://github.com/jpwarren/libsnmp claims to be pure Python. – tripleee May 24 '23 at 07:22
  • @JustinWuB `net-snmp` is the package name. Alternatively, you can try MacPorts which has lot more packages. – Shiv May 25 '23 at 07:18
  • Alternatively you can download the source and install. – Shiv May 25 '23 at 07:20

1 Answers1

0

apt-get is specific to Debian-based platforms; you may be able to find the same software for your OS, but the packaging system and probably the package names for the same software will be different.

https://packages.ubuntu.com/jammy/libsnmp-base reveals where the package comes from and what it contains. The source package is the same for both libsnmp and snmb-mibs-downloader.

Clicking through to the upstream package's home page and from there to https://net-snmp.sourceforge.io/docs/README.osX.html provides some tips for compiling on MacOS (albeit probably quite dated). In the worst case, you may need to compile the package from source yourself, which requires a fair amount of familiarity with the build toolchain on your particular OS as well as general U*x conventions. There are many, many existing questions about this broad topic on Stack Overflow, so I will not try to provide anything more than the broadest brushstrokes. Read the project's README and ask a new question if you get stuck. But you probably want to avoid this if you can, even if you have the competence to do it yourself; see the next setction.

https://formulae.brew.sh/formula/net-snmp contains the instructions for installing this software using Homebrew. Once I was aware of the upstream project's actual name, Duck Duck Going this was pretty much trivial.

You'll still need the Python header files; depending on where and how you obtained Python, this can be either trivial, or somewhat of an ordeal.

tripleee
  • 175,061
  • 34
  • 275
  • 318