1. Michael Bayer
  2. sqlalchemy

Wiki

Clone wiki

sqlalchemy / UsageRecipes / Py2exePy2app

How to use SQLAlchemy with py2exe and py2app

Problem

If you package your program with py2exe or py2app, you get the following error on execution:

ImportError: No module named sqlite

(Replace "sqlite" with the database you are using.)

Solution

"sqlite" does not refer to the sqlite3 module but to the module "sqlalchemy.databases.sqlite". Therefore you simply need to specify the package "sqlalchemy.databases.sqlite" explicitly as a needed package.

py2exe

setup.py
...
"packages": ["sqlalchemy.databases.sqlite"]
...
Command Line
python setup.py py2exe -p "sqlalchemy.databases.sqlite"

py2app

setup.py
includes=["sqlalchemy.databases.sqlite"]
Command Line
python setup.py py2app -i "sqlalchemy.databases.sqlite"

(Guessed) Explanation

py2exe/py2app failed to detect the use of SQLite because SQLAlchemy does not know which database is used until runtime.

Updated