Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build a .exe file from .py with SQLite database

Program makes appointments and places them into schedule which are written in QsQLite database. The program runs from .py but I need it to be in .exe. I have used cx_Freeze to create an .exe file, but the program does not generate the SQLite database. So here is my setup file:

from cx_Freeze import setup, Executable
import os
import sys

os.environ['TCL_LIBRARY'] = r'C:\Program Files\Python35\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Program Files\Python35\tcl\tk8.6'


build_exe_options = {"packages": [
  'os','sys','sqlite3'], 'include_files': [os.path.join(sys.base_prefix, 'DLLs', 'sqlite3.dll'), 'main.py','util.py','data.db']}

setup(
    name = "Eclients",
    version = "0.1",
    options = {"build_exe": build_exe_options},
    executables = [Executable("main.py")]
)

But database can't be opened

So,how it can be solved?

like image 479
akeg Avatar asked Dec 04 '25 04:12

akeg


2 Answers

You are not including your SQLite database file in the include_files statement. See the documentation: http://cx-freeze.readthedocs.io/en/latest/faq.html#using-data-files

A better solution, however, would be to provide an option to create the missing database file when needed. This would allow the database's SCHEMA be defined within your script, and be kept consistent with your programme logic. If it needs populating with data, this might however be a less optimal solution.

like image 181
MrGumble Avatar answered Dec 06 '25 18:12

MrGumble


Solved this problem by copying the whole 'sqldrivers' folder from C:\Program Files\Python35\Lib\site-packages\PyQt5\pluginsto main.exe directory.

like image 42
akeg Avatar answered Dec 06 '25 16:12

akeg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!