我在Python 2.7.9中製作了一些腳本文件,並另外使用了第三方庫,pyautoit 0.4。在py2exe單個EXE文件中使用第三方庫
我想提出我的腳本作爲一個單一的EXE(要在單個文件中運行,因此它們不需要安裝文件),並通過使用py2exe,嘗試這樣:
# -*- coding: utf-8 -*-
from setuptools import setup
import py2exe, sys, os
setup(name = "My Test Application",
description = "My Test Application for Windows",
version = "1.01",
console = [{"script": "myprogram.py"}],
#data_files - make directory at ./dist, not in exe file
#data_files=[("./autoit/lib", ["AutoItX3.dll"])],
options = {
"py2exe": {
"includes": ["win32api",,
"autoit",
"os" ,
"time"],
"bundle_files": 1,
}
},
zipfile = None,
)
它已成功打包到單個EXE文件中,但EXE中沒有AutoItX3.dll文件。
我發現,py2exe不能包括在它的EXE文件.dll文件,所以在我的主腳本我試圖手動導入AutoItX3.dll:
# -*- coding: utf-8 -*-
import os, sys
from ctypes import cdll
autoitdll = cdll.LoadLibrary('./modules/AutoItX3.dll')
autoitdll.run("wordpad.exe")
,它不能被加載。 (錯誤消息:
Traceback (most recent call last): File "C:/Users/win7x64kor/PycharmProjects/treesearch_27/myprogram.py", line 26, in autoitdll.run("wordpad.exe")
File "C:\Python27\lib\ctypes__init__.py", line 378, in getattr func = self.getitem(name)
File "C:\Python27\lib\ctypes__init__.py", line 383, in getitem func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'run' not found
是否有裝載庫,包括.dll文件的任何方法
或者更簡單的方法只包括「pyautoit」庫功能通過在py2exe增加一些選項,如「選項>包括? :?「AutoIt的」「一個EXE文件
感謝您的回答。我實際上使用Inno Setup作爲文件包裝器,所以如果我使用這種方法將會有2次安裝。所以我應該改變我的方法來解決這個問題。 – 2015-04-27 06:49:39