2
我一直在下面運行python代碼大約一年了。但是我們即將開始一項新工作。爲了讓我離開的部門更容易,我想將這些代碼編譯成一個.exe文件。與py2exe編譯失敗後,從Python調用MS Access模塊功能
我已經嘗試編譯與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 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-packer像pyinstaller? – 2012-03-05 14:42:43
按照Juri Robi的建議,我下載了Pyinstaller並編譯了exe。這工作得很好,沒有任何調整。 我仍然不知道爲什麼py2exe不起作用,但對我來說Pyinstaller對我來說是一個很棒的新工具,我將來會再次使用它。 Simon – PrestonDocks 2012-03-05 15:33:27