I have a Windows service that I distribute in "compiled" form, using py2exe.  This has been working well, but I recently ran into a problem.  I've converted the database access to use SQLAlchemy (SA).  This code works well from source, but the py2exe-built executable fails on startup.

The problem is related to the fact that SA uses "drivers" for various database types to encapsulate the differences among SQL dialects.  To create a connection, I pass a string starting with
"mssql+pyodbc//...", which tells SA to use the MS SQL dialect through an ODBC connection.

SA has a folder containing code for the various dialects; it parses the prefix, and calls __import__ to get the appropriate modules.  The frozen code gets an ImportError when trying to do this.

I've tried putting  'sqlalchemy.dialects' in the includes, and in the packages.  I've also tried 'sqlalchemy.dialects.mssql' and 'sqlalchemy.dialects.mssql.pyodbc'; no luck with either.

From the py2exe printed output, I've seen that it's accessing the dialects folder (at least byte compiling it).  Beyond that, I'm not sure whether or how it gets packaged in the executable.

So, I'm asking if there's some way to find out why it's failing to find the appropriate modules, or even better, how to tweak the options in setup.py to fix the problem.


Don Dwiggins
Advanced Publishing Technology