简体   繁体   中英

Error while dumping out data from sqlite3

I have used sqlite3_connection.iterdump() method to dump the sqlite3 the database.

I have written a module in python that dumps out the sqlite3 tables. The module works fine if I run it locally in my machine.

And, After creating a python package of the module using pyinstaller, if I try to dump out the database it gives an error saying

"ImportError: No module named sqlite3.dump"

Any idea how I can solve this issue. Or is there any alternative to get the sqlite3 dump.

Here is what I'm following to dump the database.

#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)

Please verify that you have have the file hooks/hook-sqlite3.py under your PyInstaller installation directory. If you don't have it please install the latest PyInstaller version .


If you're unable to install the latest version, create the file hook-sqlite3.py with the following content:

from PyInstaller.hooks.hookutils import collect_submodules
hiddenimports = collect_submodules('sqlite3')

When building, supply the path to the directory in which you placed the hook file as a value to the --additional-hooks-dir argument, as follows:

--additional-hooks-dir=<path_to_directory_of_hook_file>

As per the comment below, it seems that adding --hidden-import=sqlite3 while building works as well.

Wherever you're deploying your module, you need to install sqlite3 module first. Most likely in your local environment, the module was available in the general python library. Try working with virtualenv to avoid this type of problems and you can use pip to install all your module's requirements.

Sqlite should be included in your Python installation but it all depends what was the source, version or how Python was installed. For more details look at here : How can I install sqlite3 to Python?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM