use*_*345 5 python ms-access pyinstaller pyodbc
我用 python (pyodbc
和tkinter
)编写了一个程序。我曾经pyodbc
连接到 Microsoft Access 数据库。
有连接代码:
import pyodbc
# Microsoft Access Database File
DBfile = 'GDP.mdb'
conn = pyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};DBQ='+DBfile)
Run Code Online (Sandbox Code Playgroud)
当我在命令提示符 ( python myprogram.py
) 中编译之前启动它时,它运行良好。当编译pyinstaller
一切顺利时,不会报告任何错误。
但是当尝试启动可执行文件时,它会显示主窗口 2 秒钟,然后消失。
当我使用该-d
标志pyinstaller
打开调试模式时,它在启动可执行文件时显示以下错误:
Traceback (most recent call last):
File "<string>", line 62, in <module>
pyodbc.Error: (
'HY000', "[HY000] [Microsoft][Driver ODBC Microsoft Access]
Can't find File'(Unknown)'.
(-1811) (SQLDriverConnect); [HY000] [Microsoft][Driver ODBC Microsoft Access]
Can't find File'(Unknown)'.
(-1811)")
RC: -1 from main
Run Code Online (Sandbox Code Playgroud)
编辑
第一个错误消失了,得到了一个新错误:
Traceback (most recent call last):
File "", line 78, in
File "path\to\my\program\ build\pyi.win32\GDP\outPYZ1.pyz/Tkinter", line 1564, in wm_iconbitmap
_tkinter.TclError: bitmap "icon.ico' not defined
RC: -1 from main
Run Code Online (Sandbox Code Playgroud)
您需要使用绝对文件名,而不是本地文件:
import os
try:
currdir = os.path.dirname(os.path.abspath(__file__))
except NameError: # We are the main py2exe script, not a module
import sys
currdir = os.path.dirname(os.path.abspath(sys.argv[0]))
DBfile = os.path.join(currdir, 'GDP.mdb')
Run Code Online (Sandbox Code Playgroud)