我使用了sqlite3_connection.iterdump()方法来转储数据库的sqlite3。
我用python编写了一个模块,用于转储sqlite3表。如果我在我的机器上本地运行,这个模块就能正常工作。
而且,在使用pyinstaller创建模块的python包之后,如果我尝试将数据库转储出来,就会出现一个错误:
"ImportError: No module named sqlite3.dump"知道我能怎么解决这个问题吗。或者有其他方法可以获得sqlite3转储。
下面是我要转储数据库的内容。
#Export database
def export_database(self):
database_string = ""
for line in self.conn.iterdump():
database_string += '%s\n' % (line)
return database_string
#Import database
def import_database(self, database_string):
self.cursor.executescript(database_string)发布于 2015-09-01 12:15:23
请验证文件hooks/hook-sqlite3.py是否位于PyInstaller安装目录下。如果您没有它,请安装 version。
如果无法安装最新版本,请创建包含以下内容的文件hook-sqlite3.py:
from PyInstaller.hooks.hookutils import collect_submodules
hiddenimports = collect_submodules('sqlite3')构建时,将钩子文件放置在其中的目录的路径作为--additional-hooks-dir参数的值提供,如下所示:
--additional-hooks-dir=<path_to_directory_of_hook_file>根据下面的评论,在构建过程中添加--hidden-import=sqlite3似乎也很有效。
发布于 2015-08-29 11:30:31
无论您在哪里部署模块,都需要首先安装sqlite3模块。在您的本地环境中,该模块很可能在一般python库中可用。尝试使用virtualenv来避免这种类型的问题,您可以使用pip安装所有模块的需求。
您的Python安装中应该包括Sqlite,但这取决于源代码、版本或Python的安装方式。有关更多详细信息,请参阅此处:How can I install sqlite3 to Python?
https://stackoverflow.com/questions/32285510
复制相似问题