我已经在下面运行python代码大约一年了。但我即将开始一份新工作。为了让我要离开的部门变得简单,我想将此代码编译成.exe文件。
我尝试使用相同的结果编译Python 2.5和2.7。
但是当运行exe文件时,我收到以下错误
H:\development\DMS_Import_Data\dist>import_data.exe
Run Live or Development Import (L = Live, D = Dev, X = Exit):l
5:3:2012 10:56 Opening Live Database...
5:3:2012 10:56 Assuming Database already open
5:3:2012 10:56 Importing latest DMS Data...
Traceback (most recent call last):
File "import_data.py", line 79, in <module>
File "import_data.py", line 46, in run
File "<COMObject Access.Application>", line 2, in run
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, u'You made
an illegal function call.', None, -1, -2146820336), None)
这是python代码。问题在于此块数据类型= conn.run(“import data”)
中的最后一行import win32com.client
import pythoncom
import time
import datetime
import os
import string
class ProcessDMSData:
sleepTime = 3600
ref_date = ''
def set_ref_date(self,ref_date):
self.ref_date = ref_date
def run(self):
run_type = ""
while True:
pythoncom.CoInitialize()
check_values = ["L", "D", "X"]
while run_type.upper() not in check_values:
run_type = raw_input ("Run Live or Development Import (L = Live, D = Dev, X = Exit):")
if run_type.upper() == "L":
update_type = "Live"
database_path = "G:\\Eurofighter programme Management\\1.PM Reporting\\Production Tracking Database\\booking_planeset_tracker_data.mdb"
elif run_type.upper() == "D":
update_type = "Development"
database_path = "G:\\Eurofighter programme Management\\1.PM Reporting\\Production Tracking Database\\dev_dms_tracker_data.mdb"
elif run_type.upper() == "X":
quit()
print "%s Opening %s Database..." % (self.get_date_time(), update_type)
conn=win32com.client.Dispatch('Access.Application' )
try:
conn.OpenCurrentDatabase(database_path)
except:
print "%s Assuming Database already open" % (self.get_date_time())
pass
print "%s Importing latest DMS Data..." % (self.get_date_time())
datatype = conn.run("import_data")
任何人都可以帮助解决为什么它在python中作为脚本运行,而不是在编译为exe时运行。
由于 西蒙
答案 0 :(得分:1)
根据Juri Robi的建议,我下载了Pyinstaller并编译了exe。任何调整都适用。我仍然不知道为什么py2exe不起作用,但对我来说Pyinstaller对我来说是一个很棒的新工具,我将来会再次使用它。