如何在pyautoit中使用cx_freeze?

时间:2015-04-08 12:39:02

标签: python windows autoit cx-freeze

我想从我的Windows应用程序创建一个cx_freeze可执行文件,使用" pyautoit"模块。

pip install -U pyautoit

这是我的示例代码:

main.py

import autoit

autoit.run("notepad.exe")
autoit.win_wait_active("[CLASS:Notepad]", 3)
autoit.control_send("[CLASS:Notepad]", "Edit1", "hello world{!}")
autoit.win_close("[CLASS:Notepad]")
autoit.control_click("[Class:#32770]", "Button2")

setup.py

import sys
from cx_Freeze import setup, Executable

build_exe_options = {
    "packages": ["autoit"],
    "excludes": []
}

base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(
    name = "AutoItSample",
    version = "0.1",
    description = "Automate Notepad Editor",
    options = {"build_exe": build_exe_options},
    executables = [Executable("main.py", base=base)],
)

我在项目文件夹中使用此命令创建了构建。

python setup.py build

此模块使用模块文件夹中包含的.dll文件。

autoit
    lib
        AutoItX3.dll
    autoit.py
    ...

但cx_freeze在library.zip存档中不包含此.dll。
我试图在lib.zip存档中手动包含lib文件夹 但我也遇到了同样的错误。

http://pix.toile-libre.org/upload/original/1428496271.png

我该怎么做才能让它发挥作用?

1 个答案:

答案 0 :(得分:0)

尝试使用setup.py文件中的zip_includes选项:

import sys
from cx_Freeze import setup, Executable

build_exe_options = {
    "packages": ["autoit"],
    "excludes": [],
    "zip_includes": ['AutoITX3.dll']
}

base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(
    name = "AutoItSample",
    version = "0.1",
    description = "Automate Notepad Editor",
    options = {"build_exe": build_exe_options},
    executables = [Executable("main.py", base=base)],
)