Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix an error at start after compiling with PyInstaller got pyodbc?

I have writen a program in python (pyodbc and tkinter). I used pyodbc to connect to Microsoft Access Database.

There is the connection Code:

import pyodbc

# Microsoft Access Database File
DBfile = 'GDP.mdb'
conn = pyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};DBQ='+DBfile)

When I start it before compiling in command prompt (python myprogram.py) it works very well. When compiling with pyinstaller all goes well, no errors are reported.

But When trying to launch the executabl it shows the main window for 2 seconds which then disappears.

When I used the -d flag in pyinstaller to turn on debug mode it shows the following error when launching the executable:

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


EDIT
first error gone , got a new one :

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
like image 759
user12345 Avatar asked Sep 20 '12 14:09

user12345


1 Answers

You'll need to use an absolute filename, not a local file:

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')
like image 183
Martijn Pieters Avatar answered Sep 22 '22 18:09

Martijn Pieters