1
votes

When I package a minimal Python 2.7.1/wxPython program (Hello World) with py2exe with the most basic "configuration" and run it on a pristine Windows 7 x32 virtual machine, save "Microsoft Visual C++ 2008 Redistributable Package (x86)" installed, I get the unhelpful error:

Z:\>z:\wxhello\wxhello.exe
Traceback (most recent call last):
  File "wxhello.py", line 1, in <module>
  File "wx\__init__.pyc", line 45, in <module>
  File "wx\_core.pyc", line 4, in <module>
  File "wx\_core_.pyc", line 12, in <module>
  File "wx\_core_.pyc", line 10, in __load
ImportError: DLL load failed: The system cannot find the file specified.

All the DLLs listed at the end of running py2exe exist on the target VM save for gdiplus.dll, some wxPython library that I manually copied into the dist path.

Text and Tkinter "Hello World's" both work fine.

What's wrong? Can I get some more helpful debugging information?


The same process using cx_Freeze gives a slightly different error:

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
  File "wxhello.py", line 1, in <module>
  File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\__init__.py", line 45, in <module>
  File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 4, in <module>
  File "ExtensionLoader_wx__core_.py", line 12, in <module>
ImportError: DLL load failed: The system cannot find the file specified.

Update:

The failure of the cx_Freeze generated program to run was solved by running it off the local drive (on the VM), versus off a network share. I didn't test if that also fixed the py2exe 'binary'.

3

3 Answers

2
votes

Use cx_Freeze and be happy

1
votes

Environment:

OS: Windows-XP-5.1.2600-SP3
Python: 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)]
wxPython: 2.8.12.1 (msw-unicode)
cx_Freeze: 4.2.3

Source:

import wx

class MainWindow(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        self.panel = wx.Panel(self)
        self.button = wx.Button(self.panel, label="Hello WX!")

        self.sizer = wx.BoxSizer()
        self.sizer.Add(self.button)

        self.panel.SetSizerAndFit(self.sizer)  
        self.Show()

app = wx.App(False)
win = MainWindow(None)
app.MainLoop()

Command:

c:\Python27\Scripts\cxfreeze.bat hellowx.py

Runs without errors and produces these files in the dist directory output:

bz2.pyd
gdiplus.dll
hellowx.exe
python27.dll
unicodedata.pyd
wx._controls_.pyd
wx._core_.pyd
wx._gdi_.pyd
wx._misc_.pyd
wx._windows_.pyd
wxbase28uh_net_vc.dll
wxbase28uh_vc.dll
wxmsw28uh_adv_vc.dll
wxmsw28uh_core_vc.dll
wxmsw28uh_html_vc.dll

This runs on Windows 7 Ultimate, Version 6.1, Build 7600 virtual machine without problem.

I hope this helps you identify any problems you may have with your setup or the missing DLL.

0
votes

You can use http://www.dependencywalker.com/ to find out which DLL is missing and manually add it.