|
From: Thomas H. <th...@py...> - 2006-01-24 18:25:12
|
"Pierre Zeeman" <Pie...@ps...> writes: > Hi all, > > I have been using Python for .Net > (http://www.zope.org/Members/Brian/PythonNet/) to create a GUI for my > python code. When it came time to pack the code into an exe, running > py2exe raised the following warnings: > > "The following modules appear to be missing > ['CLR.System.Drawing', 'CLR.System.Windows.Forms']" > > The .exe was created, though, but running it immediately raised an > error: > > "An unhandled exception of type 'System.IO.FileNotFoundException' > occurred in Unknown Module. > Additional information: Could not load file or assembly 'Python.Runtime, > Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its > dependencies. The system cannot find the file specified." > > This error is resolved by placing the file "Python.Runtime.dll" into the > dist folder just created. Running the .exe then raised another error: > > "Traceback (most recent call last): > File "convertForm.py", line 6, in ? > ImportError: No module named System.Windows.Forms" > > The code in question featured the following imports to handle the > importation of the requisite dotnet modules: > > "import CLR.System.Windows.Forms as WinForms > from CLR.System.Drawing import Size, Point" > > As the traceback made clear, py2exe wasn't resolving the (implicit) > importation of the requisite dotnet dlls. All that was needed to > rectify this, however, was to add an explicit import of the CLR > namespace on its own line immediately preceding the other two imports: > > "import CLR > import CLR.System.Windows.Forms as WinForms > from CLR.System.Drawing import Size, Point" > > Now everything is working fine. It still raises that first warning but > this can be ignored. > > I hope this helps someone else, Pierre, thanks for posting this. I wasn't aware that it is possible to use the Python.NET extensions to make a Windows GUI for python code. Cool! For the py2exe issue, CLR.dll seems to replace Python's __import__ function with its own, but your recipe works fine. Maybe it should go into the py2exe wiki? Thomas |