使用 py2exe 编译失败后从 Python 调用 MS Access 模块函数 [英] Call MS Access module function from Python after compiling with py2exe fails

查看:61
本文介绍了使用 py2exe 编译失败后从 Python 调用 MS Access 模块函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经运行下面的 python 代码大约一年了.但我即将换一份新工作.为了方便我离开的部门,我想把这段代码编译成一个 .exe 文件.

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.

我尝试过针对 Python 2.5 和 2.7 进行编译,结果相同.

I have tried compiling against Python 2.5 and 2.7 with the same results.

但是在运行exe文件时出现以下错误

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)

这是python代码.问题出在此块中的最后一行 datatype = conn.run("import data")

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")

任何人都可以帮助解释为什么它可以在 python 中作为脚本运行,而不是在它被编译为 exe 时运行.

Can anyone help with why this works running as a script in python but not when it has been compiled to an exe.

谢谢西蒙

推荐答案

按照 Juri Robi 的建议,我下载了 Pyinstaller 并编译了 exe.这在没有任何调整的情况下工作得很好.我仍然不知道为什么 py2exe 不起作用,但对我来说 Pyinstaller 对我来说是一个很棒的新工具,我将来会再次使用.

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.

这篇关于使用 py2exe 编译失败后从 Python 调用 MS Access 模块函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆