I have been running the python code below for approx a year now. But am about to move onto a new job. In order to make things easy for the department I am leaving, I want to compile this code into a .exe file.
I have tried compiling against Python 2.5 and 2.7 with the same results.
But when when running the exe file I get the following error
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)
Here is the python code. The problem is with the last line in this block datatype = 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")
Can anyone help with why this works running as a script in python but not when it has been compiled to an exe.
Thanks Simon
Following the advice from Juri Robi, I downloaded Pyinstaller and compiled the exe. This worked just fine with out any ajustments. I still dont know why py2exe did not work but for me Pyinstaller is a great new tool for me that I will be using again in the future.