Question

When I try to transform my script in an executable, I get this error after it's done:

Traceback (most recent call last):
  File "shd-WinResize.py", line 4, in <module>
  File "zipextimporter.pyo", line 98, in load_module
ImportError: MemoryLoadLibrary failed loading win32api.pyd

I'm using this script to convert:

from distutils.core import setup
import py2exe
import sys

sys.argv.append('py2exe')

setup(
    options = {'py2exe': dict(bundle_files=1, optimize=2)},
    windows = ["shd-WinResize.py"],
    zipfile = None,
    )

and here is the source of my program:

import pyHook
import pythoncom

import win32api
import win32console
import win32gui

hideConsole = win32console.GetConsoleWindow()
win32gui.ShowWindow(hideConsole, 0)


def OnKeyboardEvent(event):
    if event.Ascii == 49:
        windowFocused = win32gui.GetForegroundWindow()
        win32gui.MoveWindow(windowFocused, 0, 0, 1440, 900, True)
    elif event.Ascii == 50:
        windowFocused = win32gui.GetForegroundWindow()
        win32gui.MoveWindow(windowFocused, 0, 0, 1366, 768, True)
    elif event.Ascii == 51:
        windowFocused = win32gui.GetForegroundWindow()
        win32gui.MoveWindow(windowFocused, 0, 0, 1280, 1024, True)
    elif event.Ascii == 52:
        windowFocused = win32gui.GetForegroundWindow()
        win32gui.MoveWindow(windowFocused, 0, 0, 1280, 960, True)
    elif event.Ascii == 53:
        windowFocused = win32gui.GetForegroundWindow()
        win32gui.MoveWindow(windowFocused, 0, 0, 1280, 800, True)
    elif event.Ascii == 54:
        windowFocused = win32gui.GetForegroundWindow()
        win32gui.MoveWindow(windowFocused, 0, 0, 1280, 768, True)
    elif event.Ascii == 55:
        windowFocused = win32gui.GetForegroundWindow()
        win32gui.MoveWindow(windowFocused, 0, 0, 1152, 864, True)
    elif event.Ascii == 56:
        windowFocused = win32gui.GetForegroundWindow()
        win32gui.MoveWindow(windowFocused, 0, 0, 1024, 768, True)
    elif event.Ascii == 57:
        windowFocused = win32gui.GetForegroundWindow()
        win32gui.MoveWindow(windowFocused, 0, 0, 800, 600, True)
    elif event.Ascii == 48:
        windowFocused = win32gui.GetForegroundWindow()
        win32gui.MoveWindow(windowFocused, 0, 0, 640, 480, True)


hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()

what is wrong with it?

I want compressed and I want bundle... What should I do?

Was it helpful?

Solution

PY2EXE in Windows Vista and Windows 7 apparantly gets confused by some of the DLLs it needs to import. Here's the solution, which was inspired by another post:

from distutils.core import setup
import py2exe, sys, os

sys.argv.append('py2exe')

setup(
    options={
        "py2exe":{
            "dll_excludes":[ "mswsock.dll", "powrprof.dll"],
            'bundle_files': 1
        }
    },
    windows = [{'script': "scriptName.py"}],
    zipfile = None,
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top