Just trying one of the official documentation site examples:
from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
getCm
Got the same error "could not get source code". There is an issue about that created on Pyinstaller github page: https://github.com/pyinstaller/pyinstaller/issues/1945 Solution is to include ply to spec file as it is described in link you mentioned: Can't get pysnmp to work with pyinstaller by adding "PyInstaller.utils.hooks.collect_submodules('ply')" to hiddenimports
And make sure ply version is >= 3.9!
My spec file looks pretty much same except Analysis part:
a = Analysis(['main.py'],
binaries=None,
datas=PyInstaller.utils.hooks.collect_data_files('pysnmp') + \
hiddenimports=PyInstaller.utils.hooks.collect_submodules('pysmi')+\
PyInstaller.utils.hooks.collect_submodules('ply') + \
PyInstaller.utils.hooks.collect_submodules('pyasn1') + \
PyInstaller.utils.hooks.collect_submodules('pysnmp'),
hookspath=None,
runtime_hooks=None,
excludes=None,
win_no_prefer_redirects=None,
win_private_assemblies=None,
cipher=block_cipher)