Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
cx#u冻结python sqlite3数据库不';build.exe之后无法工作?_Python_Sqlite_Cx Freeze_Qsqldatabase - Fatal编程技术网

cx#u冻结python sqlite3数据库不';build.exe之后无法工作?

cx#u冻结python sqlite3数据库不';build.exe之后无法工作?,python,sqlite,cx-freeze,qsqldatabase,Python,Sqlite,Cx Freeze,Qsqldatabase,基本上,我有一个使用sqlite3数据库的pyqt应用程序,现在我使用Cx_Freeze将其转换为可执行文件 我发现,当数据库和查询以.py格式运行时,它们运行得非常好,但是在cx_freeze转换为.exe之后,gui工作正常,但数据库不会响应任何查询 以下是安装脚本的代码: from cx_Freeze import setup, Executable # Dependencies are automatically detected, but it might need # fine t

基本上,我有一个使用sqlite3数据库的pyqt应用程序,现在我使用Cx_Freeze将其转换为可执行文件

我发现,当数据库和查询以.py格式运行时,它们运行得非常好,但是在cx_freeze转换为.exe之后,gui工作正常,但数据库不会响应任何查询

以下是安装脚本的代码:

from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = [],
    excludes = [],
    includes = ["sip", "PyQt5.QtSql"],
    include_files = ["tpaData.db"])

import sys
base = 'Win32GUI' if sys.platform=='win32' else None

executables = [Executable('testTpa.py', base=base)]

setup(
    name='Tpa APP',
    version = '0.1',
    description = 'A PyQt TPA Program',
    options = dict(build_exe = buildOptions),
    executables = executables
)
下面是我用来实例化db和应用程序的代码:

def __init__(self, dialog):
        Ui_Form.__init__(self)
        self.setupUi(dialog)
        self.createConnection()

def createConnection(self):
        self.db = QtSql.QSqlDatabase.addDatabase('QSQLITE')
        self.db.setDatabaseName("tpaData.db")
        self.db.open()
        self.query = QtSql.QSqlQuery()
        self.query.exec_("create table doses(dose text, bolus text, discard text, remaining text, time1 text, time2 text, time3 text, comment text)")
稍后在应用程序中,我使用query.prepare方法生成输入字符串,然后使用query.bind方法将值绑定到query.prepare字符串。最后,我使用query.exec_389;()提交准备好的字符串

在开发环境(.py文件)工作时,只需在cx_冻结之后,它就会失败


提前感谢您的帮助。

在这里找到了我的问题的解决方案,只是使用py2exe或pyinstaller使其可分发,显然我使用的Cx\u freeze版本与我的python版本不兼容。

Cx\u freeze不会复制包含库数据库驱动程序的文件夹。例如,如果您从“*C:\Python27\Lib\site packages\PyQt4\plugins\sqldrivers*”复制它们,并且在构建目录中的目录为“sqldrivers”,则它们应该可以工作。我有一个类似的例子,但是使用PySide-它成功了。

我将尝试一下PySide,因为它非常接近qt4。谢谢你的提示!