I download the repo for pythonnet and built the project using ReleaseWin on platform x86 using visual studio 2012.
pythonnet works fine but once i freeze the app using cx_freeze the app crashes.
It worked well with the source forge version but fails on windows 8 and 8.1.
After googling around i found that building the repo using x86 solves the problem.
I've tried cx_freeze, py2exe and pyinstaller. I'm using Python 2.7 64bit, Windows 7 64bit. and I have a bunch of .Net frameworks installed, including 4 and 4.5.
Is it at all possible to create an exe that using python.net?
@konstantin-popov feel free to submit a pull request to cx_freeze to implement this hook based on pyinstaller implementation. We cannot do anything about this in pythonnet without breaking a lot of code.
We cannot do anything about this in pythonnet without breaking a lot of code.
Sure. My reply was not a call to action, only a recipe how to deal with this specific problem - actually not with patching cx_freeze, but with adding a file to build using configuration options (option 'include_files').
The ticket you mentioned is actually about a different problem - failing to import custom .NET libraries in frozen app.
I do update sys.path and clr.AddReference('customlib') throws no exceptions - the problem appears later in code when importing the assembly.
I guess pythonnet hooks into python import system to load .NET assemblies, but after freezing the app with cx_freeze in doesn't work for some reason.
@konstantin-popov minimum reproducible example would be handy. Also make sure that your library does not reference other custom assemblies, maybe even during runtime.
Activity
jfbramboll commented on Mar 20, 2015
I'm getting the exact same error as here: http://stackoverflow.com/questions/26110026/pyinstaller-and-pythonnet-clr
I've tried cx_freeze, py2exe and pyinstaller. I'm using Python 2.7 64bit, Windows 7 64bit. and I have a bunch of .Net frameworks installed, including 4 and 4.5.
Is it at all possible to create an exe that using python.net?
den-run-ai commented on Jan 30, 2016
@jfbramboll @kelvinomolumo PyInstaller should provide a hook to include pythonnet:
pyinstaller/pyinstaller#637
it is reportedly working for people here:
https://groups.google.com/forum/#!topic/pyinstaller/juS48yx3XyE
I am not sure about cx_freeze
den-run-ai commented on Aug 29, 2016
pyinstaller has been updated to include proper clr (pythonnet) hook:
pyinstaller/pyinstaller#1801
konstantin-popov commented on Mar 6, 2017
In order to stop crashing with cx_freeze you need to manually add Python.Runtime.dll file from pythonnet package to your binary directory.
den-run-ai commented on Mar 6, 2017
@konstantin-popov does cx_freeze allow configuring hooks for various packages so that this works by default?
konstantin-popov commented on Mar 6, 2017
Not sure, but I think it does, looking at this: https://github.com/anthony-tuininga/cx_Freeze/blob/master/cx_Freeze/hooks.py
den-run-ai commented on Mar 6, 2017
@konstantin-popov feel free to submit a pull request to cx_freeze to implement this hook based on pyinstaller implementation. We cannot do anything about this in pythonnet without breaking a lot of code.
marcelotduarte/cx_Freeze#249
konstantin-popov commented on Mar 6, 2017
Sure. My reply was not a call to action, only a recipe how to deal with this specific problem - actually not with patching cx_freeze, but with adding a file to build using configuration options (option 'include_files').
The ticket you mentioned is actually about a different problem - failing to import custom .NET libraries in frozen app.
den-run-ai commented on Mar 6, 2017
@konstantin-popov you need to update sys.path in order to custom load your .NET assemblies. See fairly complicated example for pyinstaller here:
#325
konstantin-popov commented on Mar 7, 2017
I do update sys.path and clr.AddReference('customlib') throws no exceptions - the problem appears later in code when importing the assembly.
I guess pythonnet hooks into python import system to load .NET assemblies, but after freezing the app with cx_freeze in doesn't work for some reason.
vmuriart commented on Mar 7, 2017
Is there a traceback available?
den-run-ai commented on Mar 7, 2017
@konstantin-popov minimum reproducible example would be handy. Also make sure that your library does not reference other custom assemblies, maybe even during runtime.
konstantin-popov commented on Mar 10, 2017
That was exactly the thing. The library was external so I didn't guess it referenced somethine else. Thanks @denfromufa!
P.S. PR with a hook for pythonnet in cx_freeze
anthony-tuininga commented on Mar 11, 2017
Pull request merged.
den-run-ai commented on Mar 11, 2017
@jfbramboll @kelvinomolumo can you please verify that the pythonnet hook is now working in cx_freeze? @anthony-tuininga @konstantin-popov thanks for implementing this!
Anyway if any issues come up we can reopen this issue.