![]() |
cx_freeze setup.py error: No module __SNMP-FRAMEWORK-MIB - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: cx_freeze setup.py error: No module __SNMP-FRAMEWORK-MIB (/thread-8403.html) |
cx_freeze setup.py error: No module __SNMP-FRAMEWORK-MIB - nacho - Feb-18-2018 Hello all. Firstly I run the following: Windows 10 Enterprise 64-bit Python 3.6.4 pysnmp 4.4.4 pyasn1 0.2.3 paramiko for ssh tkinter as a GUI All on Visual Studio Code v1.20.1 I actually raised this in a Stack Overflow forum (MibNotFoundError) and was advised (I think) to come here as I couldn't locate any online forums specifically dedicated to cx_freeze. I made an app that adds/removes vlans and sends an snmp trap each time this is done. It all works fine when running just as a python script. When I assemble the exe using cx_freeze everything works EXCEPT that it doesn't send the trap and presents with the following error: Traceback (most recent call last): File "C:\Python\Python36-32\lib\tkinter\__init__.py", line 1699, in __call__ return self.func(*args) File "snmpTester.py", line 56, in LabAccess File "snmpTester.py", line 34, in sendTrap File "C:\Python\Python36-32\lib\site-packages\pysnmp\entity\engine.py", line 91, in __init__ '__SNMP-FRAMEWORK-MIB', 'snmpEngineMaxMessageSize') File "C:\Python\Python36-32\lib\site-packages\pysnmp\smi\builder.py", line 409, in importSymbols 'No module %s loaded at %s' % (modName, self) pysnmp.smi.error.MibNotFoundError: No module __SNMP-FRAMEWORK-MIB loaded at <pysnmp.smi.builder.MibBuilder object at 0x03FD51B0> When I enter the "python snmpSetup.py build" command to create the exe file, among all the other stuff that shows in the cmd window, I do see the above module successfully copied over: <snip> copying C:\Python\Python36-32\Lib\site-packages\pysnmp\smi\mibs\instances\__SNMP-FRAMEWORK-MIB.py -> build\exe.win32-3.6\mibs\instances\__SNMP-FRAMEWORK-MIB.py <snip> I have confirmed that the "__SNMP-FRAMEWORK-MIB.py" file is located in the instances folder as per the code in my setup.py file: options = { 'build_exe': { #'packages':packages, 'include_files':[ os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'), os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'), 'C:\\Python\\Python36-32\\Lib\\site-packages\\idna', 'C:\\Python\\Python36-32\\Lib\\site-packages\\pysnmp\\smi\\mibs', 'C:\\Python\\Python36-32\\Lib\\site-packages\\pysnmp\\smi\\mibs\\instances' ], }, }Can anyone see where I'm going wrong? If you need more info please let me know as I didn't want to make my first post here too long and there are already many details in the Stack Overflow post that I did. Thanks for any help Cheers RE: cx_freeze setup.py error: No module __SNMP-FRAMEWORK-MIB - snippsat - Feb-18-2018 I did a test but use Pyinstaller. Same error so the problem is pysnmp and that it don't find where mibs is installed.Give full path and add to hiddenimports fix in test i did. I run all in virtual environment using pipenv. Example: pipenv install pyinstaller pipenv install pypiwin32 pipenv install pysnmp pipenv install snmpclitoolsActivate pipenv shell So now try to make exe of demo code in pysnmp. C:\1\exe_env λ pyinstaller --onefile pn.pyGive same error as you got. The fix,every time Pyinstaller run it generate a .spec file.Here is the fix in .spec file that worked for me. C:\1\exe_env λ pyinstaller --clean pn.specThe path is where mibs is placed in virtual environment.# -*- mode: python -*- hiddenimports = ['pysnmp.smi.exval','pysnmp.cache'] a = Analysis(['pn.py'], pathex=['C:/1/exe_env'], hiddenimports=hiddenimports, hookspath=None, runtime_hooks=None, ) x = Tree('C:/Users/Tom/.virtualenvs/exe_env-Y6bgVtdX/Lib/site-packages/pysnmp/smi/mibs',prefix='pysnmp/smi/mibs',excludes='.py') pyz = PYZ(a.pure) exe = EXE(pyz, a.scripts, a.binaries, a.zipfiles, a.datas, x, name='app', debug=False, strip=None, upx=True, console=True ) RE: cx_freeze setup.py error: No module __SNMP-FRAMEWORK-MIB - nacho - Feb-19-2018 Thanks snippsat for the reply. Unfortunately it's pretty much over my head. Apologies but I should have mentioned here I am very much a newbie to python. Are you saying I should use pyinstaller instead of cx_freeze? or do I use the fix you recommend in cx_freeze? I don't see any "spec" files when cx_freeze has completed it's work. I'm having trouble understanding what I need do. From your code above is "name" = 'the_name_of_my_app'? and "Tree" is the path to the mibs? Thanks again. RE: cx_freeze setup.py error: No module __SNMP-FRAMEWORK-MIB - snippsat - Feb-19-2018 (Feb-19-2018, 12:05 AM)nacho Wrote: Are you saying I should use pyinstaller instead of cx_freeze? or do I use the fix you recommend in cx_freeze?Did a quick test with cx_freeze but there got other errors after same imports and added path. So yes you should use Pyinstaller,look at Doc. RE: cx_freeze setup.py error: No module __SNMP-FRAMEWORK-MIB - nacho - Feb-19-2018 Ok. I've installed pyinstaller and run it on the python script. I then made the change to the spec file but I'm getting a new error now: C:\Users\netcomm\Documents\TerryTestPython>pyinstaller snmpTester.spec 122 INFO: PyInstaller: 3.3.1 123 INFO: Python: 3.6.4 126 INFO: Platform: Windows-10-10.0.14393-SP0 130 INFO: UPX is not available. 130 INFO: Removing temporary files and cleaning cache in C:\Users\netcomm\AppData\Roaming\pyinstaller Traceback (most recent call last): File "C:\Python\Python36-32\Scripts\pyinstaller-script.py", line 11, in <module> load_entry_point('PyInstaller==3.3.1', 'console_scripts', 'pyinstaller')() File "c:\python\python36-32\lib\site-packages\PyInstaller\__main__.py", line 94, in run run_build(pyi_config, spec_file, **vars(args)) File "c:\python\python36-32\lib\site-packages\PyInstaller\__main__.py", line 46, in run_build PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs) File "c:\python\python36-32\lib\site-packages\PyInstaller\building\build_main.py", line 791, in main build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build')) File "c:\python\python36-32\lib\site-packages\PyInstaller\building\build_main.py", line 737, in build exec(text, spec_namespace) File "<string>", line 28 SyntaxError: positional argument follows keyword argument C:\Users\netcomm\Documents\TerryTestPython> Here is the current spec file (I have tried using both / and \\ for the path names and both give the same error above: # -*- mode: python -*- block_cipher = None hiddenimports = ['pysnmp.smi.exval','pysnmp.cache'] a = Analysis(['snmpTester.py'], pathex=['C:/Users/netcomm/Documents/TerryTestPython'], binaries=[], datas=[], hiddenimports=[], hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher) x = Tree('C:/Python/Python36-32/Lib/site-packages/pysnmp/smi/mibs',prefix='pysnmp/smi/mibs',excludes='.py') pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) exe = EXE(pyz, a.scripts, exclude_binaries=True, name='snmpTester', debug=False, strip=False, upx=True, x, console=True ) coll = COLLECT(exe, a.binaries, a.zipfiles, a.datas, strip=False, upx=True, name='snmpTester')Not sure where I go from here. Do you have any other ideas? Thanks. RE: cx_freeze setup.py error: No module __SNMP-FRAMEWORK-MIB - snippsat - Feb-19-2018 Just copy my .spec file and add your own path as in your spec file. pyinstaller --clean pn.spec
RE: cx_freeze setup.py error: No module __SNMP-FRAMEWORK-MIB - nacho - Feb-19-2018 Thanks. Ok so I'm getting closer. That now appears to work ok on the snmpTester.py script I took from my main app. However I get a different error when I try pyinstaller on the main app so I think there is maybe another error now (perhaps not related to snmp?): C:\Users\netcomm\Documents\TerryTestPython>pyinstaller --clean testerButton.spec 129 INFO: PyInstaller: 3.3.1 129 INFO: Python: 3.6.4 132 INFO: Platform: Windows-10-10.0.14393-SP0 138 INFO: UPX is not available. 139 INFO: Removing temporary files and cleaning cache in C:\Users\netcomm\AppData\Roaming\pyinstaller Traceback (most recent call last): File "C:\Python\Python36-32\Scripts\pyinstaller-script.py", line 11, in <module> load_entry_point('PyInstaller==3.3.1', 'console_scripts', 'pyinstaller')() File "c:\python\python36-32\lib\site-packages\PyInstaller\__main__.py", line 94, in run run_build(pyi_config, spec_file, **vars(args)) File "c:\python\python36-32\lib\site-packages\PyInstaller\__main__.py", line 46, in run_build PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs) File "c:\python\python36-32\lib\site-packages\PyInstaller\building\build_main.py", line 791, in main build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build')) File "c:\python\python36-32\lib\site-packages\PyInstaller\building\build_main.py", line 737, in build exec(text, spec_namespace) File "<string>", line 10 SyntaxError: keyword argument repeated Something to do with "main.py" I'm guessing. Any ideas? Thanks >>> SCRATCH THAT. I made an error and inadvertantly pasted the path into the spec file twice. I have fixed that and it's WORKING! Thanks heaps for your help today. I really appreciate it. Hi. Do I need to do anything else to "close" this thread? or mark it as "Answered"? RE: cx_freeze setup.py error: No module __SNMP-FRAMEWORK-MIB - snippsat - Feb-19-2018 (Feb-19-2018, 03:25 AM)nacho Wrote: I have fixed that and it's WORKING!Good,there is no closed Thread or marked as "Answered" just leave it as it is ![]() RE: cx_freeze setup.py error: No module __SNMP-FRAMEWORK-MIB - njmatt415 - Jul-26-2019 (Feb-19-2018, 03:25 AM)nacho Wrote: Thanks. Ok so I'm getting closer. That now appears to work ok on the snmpTester.py script I took from my main app. I have this exact same problem with pyinstaller. I followed all of these instructions very closely, build is successful, but when I run the build I'm getting the following error: [13565] Error loading Python lib '/tmp/_MEI3f3yDW/libpython2.7.so.1.0': dlopen: /tmp/_MEI3f3yDW/libpython2.7.so.1.0: cannot open shared object file: No such file or directory Did you get this at all? What could it be? |