1

当我尝试将脚本转换为可执行文件时,完成后出现此错误:

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

它有什么问题?

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

4

1 回答 1

0

Windows Vista 和 Windows 7 中的 PY2EXE 显然被它需要导入的一些 DLL 搞糊涂了。这是受另一篇文章启发的解决方案:

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,
)
于 2011-05-10T16:56:04.337 回答