• Uncategorized

About linux : Problem-while-bundling-pythonnet-project-into-executable-file-on-Ubuntu1804

Question Detail

I have a VSCode project which used python and .NET intergration (With pythonnet) under Windows10, and it runs successfully both in VSCode debug mode and bundle mode (pyinstaller). Now I want to implement the project on Ubuntu18.04 with following configuration:

  1. Python version: 3.6.9
  2. mono version:
  3. pythonnet version: 2.5.2
  4. dotnet version: 3.1.416

After the preparation for pythonnet is finished, I also create a VSCode project on Ubuntu and run the code successfully in debug mode. But when I tried to use pyinstaller to create a bundled executable file, it did not work successfully:

xxx@ubuntu001:~/Workspace/temp/bab_debugger_v2p0_2022010101/ui_python/dist$ ./bab_debugger_v2p0
Press any key to continue ...

Output information:

Traceback (most recent call last):
  File "bab_debugger_v2p0.py", line 35, in <module>
ImportError: System.TypeInitializationException: The type initializer for 'Sys' threw an exception. ---> System.DllNotFoundException: /usr/lib/../lib/libmono-native.so assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) Interop+Sys.LChflagsCanSetHiddenFlag()
  at Interop+Sys..cctor () [0x00000] in <533173d24dae460899d2b10975534bb0>:0 
   --- End of inner exception stack trace ---
  at Interop.GetRandomBytes (System.Byte* buffer, System.Int32 length) [0x00000] in <533173d24dae460899d2b10975534bb0>:0 
  at System.Guid.FastNewGuidArray () [0x00020] in <533173d24dae460899d2b10975534bb0>:0 
  at System.Reflection.Emit.ModuleBuilder..ctor (System.Reflection.Emit.AssemblyBuilder assb, System.String name, System.String fullyqname, System.Boolean emitSymbolInfo, System.Boolean transient) [0x00035] in <533173d24dae460899d2b10975534bb0>:0 
  at System.Reflection.Emit.AssemblyBuilder.DefineDynamicModule (System.String name, System.String fileName, System.Boolean emitSymbolInfo, System.Boolean transient) [0x0005b] in <533173d24dae460899d2b10975534bb0>:0 
  at System.Reflection.Emit.AssemblyBuilder.DefineDynamicModule (System.String name) [0x00000] in <533173d24dae460899d2b10975534bb0>:0 
  at Python.Runtime.CodeGenerator..ctor () [0x0002b] in <2b91d2ccf0934488b2c125769adaa0cc>:0 
  at Python.Runtime.DelegateManager..ctor () [0x00061] in <2b91d2ccf0934488b2c125769adaa0cc>:0 
  at Python.Runtime.PythonEngine.Initialize (System.Collections.Generic.IEnumerable`1[T] args, System.Boolean setSysArgv, System.Boolean initSigs) [0x0000a] in <2b91d2ccf0934488b2c125769adaa0cc>:0 
  at Python.Runtime.PythonEngine.Initialize (System.Boolean setSysArgv, System.Boolean initSigs) [0x00005] in <2b91d2ccf0934488b2c125769adaa0cc>:0 
  at Python.Runtime.PythonEngine.InitExt () [0x00000] in <2b91d2ccf0934488b2c125769adaa0cc>:0 
[14057] Failed to execute script 'bab_debugger_v2p0' due to unhandled exception!

I check the code of bab_debugger_v2p0.py file and the contents of line 35 is “import clr”. It seems like the mono is not integrated into the bundled file successfully. I tried to add libmono-native.so by modifying the bab_debugger_v2p0.spec file but the result is still the same. How can I bundle the pythonnet project with mono correctly by using pyinstaller on Ubuntu? Or is there any other tools which can make correct bundling?

Question Answer

No answer for now.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.