Reputation: 23
I've programed a code in python that uses a sqlite database. Now i need to send an .exe file to other people and they have to run it properly only using the .exe file and without the .db files. But i don't know how to create an executable that includes the sqlite database. Any help?
Upvotes: 0
Views: 3467
Reputation: 148910
You can use installers to convert a Python script into a Windows .exe file. Most of them are able to add files to the bundle.
So with PyInstaller, you could:
at build time:
data
sub-field of Analysys in the spec fileat run time:
the PyInstaller loader will extract the bundle into a temporary folder
the python code can get the path of that folder in sys._MEIPASS
from there on, it knows the path of the dump and can load it into a in-memory database:
import sqlite3
...
con = sqlite3.connect(':memory:')
con.executescript(open(path_to_dump_file).read())
con
now gives access to the content of the database...
This only gives hints on the how-to, but a detailed recipe would really depend on the installer and on your applicaiton.
Upvotes: 1