使用 SQLite 数据库从 .py 构建一个 .exe 文件
Build a .exe file from .py with SQLite database
程序进行约会并将它们放入写在 QsQLite 数据库中的日程表中。该程序从 .py 运行,但我需要它在 .exe 中。
我已经使用 cx_Freeze 创建了一个 .exe 文件,但是程序没有生成 SQLite 数据库。
所以这是我的设置文件:
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")]
)
但是数据库打不开
那么,如何解决呢?
您没有在 include_files
语句中包含您的 SQLite 数据库文件。请参阅文档:http://cx-freeze.readthedocs.io/en/latest/faq.html#using-data-files
但是,更好的解决方案是提供一个选项,以便在需要时创建丢失的数据库文件。这将允许在您的脚本中定义数据库的 SCHEMA,并与您的程序逻辑保持一致。如果它需要填充数据,这可能不是最佳解决方案。
通过将整个 'sqldrivers' 文件夹从 C:\Program Files\Python35\Lib\site-packages\PyQt5\plugins
复制到 main.exe 目录解决了这个问题。
程序进行约会并将它们放入写在 QsQLite 数据库中的日程表中。该程序从 .py 运行,但我需要它在 .exe 中。 我已经使用 cx_Freeze 创建了一个 .exe 文件,但是程序没有生成 SQLite 数据库。 所以这是我的设置文件:
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")]
)
但是数据库打不开
那么,如何解决呢?
您没有在 include_files
语句中包含您的 SQLite 数据库文件。请参阅文档:http://cx-freeze.readthedocs.io/en/latest/faq.html#using-data-files
但是,更好的解决方案是提供一个选项,以便在需要时创建丢失的数据库文件。这将允许在您的脚本中定义数据库的 SCHEMA,并与您的程序逻辑保持一致。如果它需要填充数据,这可能不是最佳解决方案。
通过将整个 'sqldrivers' 文件夹从 C:\Program Files\Python35\Lib\site-packages\PyQt5\plugins
复制到 main.exe 目录解决了这个问题。