我使用了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)
最佳答案
请验证您的 PyInstaller 安装目录下是否有文件 hooks/hook-sqlite3.py
。如果您没有,请安装 latest PyInstaller version .
如果您无法安装最新版本,请创建包含以下内容的文件hook-sqlite3.py
:
from PyInstaller.hooks.hookutils import collect_submodules
hiddenimports = collect_submodules('sqlite3')
构建时,将放置 Hook 文件的目录路径作为 --additional-hooks-dir
参数的值提供,如下所示:
--additional-hooks-dir=<path_to_directory_of_hook_file>
<小时/>
根据下面的评论,似乎在构建时添加 --hidden-import=sqlite3
也有效。
关于python - 从 sqlite3 转储数据时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32285510/