PyInstaller does NOT work when including Pysnmp

后端 未结 3 1594
梦谈多话
梦谈多话 2020-12-22 00:48

Just trying one of the official documentation site examples:

from pysnmp.hlapi import *

errorIndication, errorStatus, errorIndex, varBinds = next(
    getCm         


        
相关标签:
3条回答
  • 2020-12-22 01:27

    To make Jeremy's answer portable, you can modify your specfile like this diff:

    + import os.path
    + import pysmi
    + import pysnmp.smi.mibs
    
    + def module_base(module):
    +   return os.path.abspath(os.path.join(module.__file__, os.pardir))
    
      coll = COLLECT(
          exe,
          a.binaries,
          a.zipfiles,
          a.datas,
    +     Tree(module_base(pysmi), prefix='pysmi'),
    +     Tree(module_base(pysnmp.smi.mibs), prefix='pysnmp/smi/mibs'),
          ...
    

    EDIT: turn out adding these to hiddenimports solved the problem for me:

    'pysnmp.smi.mibs', 'pysnmp.smi.mibs.instances', 'pysnmp.smi.exval', 'pysnmp.cache'
    
    0 讨论(0)
  • 2020-12-22 01:44

    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)
    
    0 讨论(0)
  • 2020-12-22 01:48

    I had the same problem and managed to get it working by including the pysmi files as a Tree just like the pysnmp mibs.

    My pyinstaller spec file ended up like:

    ...
    
    x = Tree(os.getcwd()+'/.pyenv/Lib/site-packages/pysnmp/smi/mibs',prefix='pysnmp/smi/mibs')
    y = Tree(os.getcwd()+'/.pyenv/Lib/site-packages/pysmi',prefix='pysmi')
    
    ...
    
    exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          x,y,
    
    ...
    

    While this worked I actually solved it in another way by using an older version of pysnmp v4.2.5 which doesn't depend on pysmi

    0 讨论(0)
提交回复
热议问题