将.py转换为.exe时出错

时间:2010-02-26 04:55:54

标签: python winapi py2exe

当我尝试在可执行文件中转换我的脚本时,我在完成后会收到此错误:

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

我正在使用此脚本进行转换:

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,
    )

这是我的计划的来源:

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()

它出了什么问题?

我想要压缩,我想要捆绑... 我该怎么办?

1 个答案:

答案 0 :(得分:0)

Windows Vista和Windows 7中的PY2EXE显然被它需要导入的一些DLL搞糊涂了。这是解决方案,其灵感来自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,
)