pewee.py sqlite:Operational error Unable to open database file

Traceback (most recent call last):
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 3035, in connect
    self._state.set_connection(self._connect())
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 3371, in _connect
    isolation_level=None, **self.connect_params)
sqlite3.OperationalError: unable to open database file

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 3097, in execute_sql
    cursor = self.cursor(commit)
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 3081, in cursor
    self.connect()
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 3038, in connect
    self._initialize_connection(self._state.conn)
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 2873, in __exit__
    reraise(new_type, new_type(exc_value, *exc_args), traceback)
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 183, in reraise
    raise value.with_traceback(tb)
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 3035, in connect
    self._state.set_connection(self._connect())
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 3371, in _connect
    isolation_level=None, **self.connect_params)
peewee.OperationalError: unable to open database file

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/usr/lib/python3.6/multiprocessing/process.py", line 93, in run
    self._target(*self._args, **self._kwargs)
  File "app.py", line 87, in recognize
    recognizer.main()
  File "/home/corpus/flaskProject/processing/extensions/prodigy_annotation.py", line 23, in main
    host="0.0.0.0", port=self.port)
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/prodigy/__init__.py", line 44, in serve
    controller = loaded_recipe(*recipe_args)
  File "cython_src/prodigy/core.pyx", line 327, in prodigy.core.recipe.recipe_decorator.recipe_proxy
  File "cython_src/prodigy/core.pyx", line 116, in prodigy.core.Controller.__init__
  File "cython_src/prodigy/core.pyx", line 285, in prodigy.core.Controller.connect_db
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/prodigy/components/db.py", line 207, in __contains__
    has_ds = bool(Dataset.get(Dataset.name == name))
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 6384, in get
    return sq.get()
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 6807, in get
    return clone.execute(database)[0]
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 1886, in inner
    return method(self, database, *args, **kwargs)
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 1957, in execute
    return self._execute(database)
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 2129, in _execute
    cursor = database.execute(self)
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 3112, in execute
    return self.execute_sql(sql, params, commit=commit)
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 3106, in execute_sql
    self.commit()
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 2873, in __exit__
    reraise(new_type, new_type(exc_value, *exc_args), traceback)
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 183, in reraise
    raise value.with_traceback(tb)
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 3097, in execute_sql
    cursor = self.cursor(commit)
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 3081, in cursor
    self.connect()
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 3038, in connect
    self._initialize_connection(self._state.conn)
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 2873, in __exit__
    reraise(new_type, new_type(exc_value, *exc_args), traceback)
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 183, in reraise
    raise value.with_traceback(tb)
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 3035, in connect
    self._state.set_connection(self._connect())
  File "/home/corpus/flaskProject/venv/lib/python3.6/site-packages/peewee.py", line 3371, in _connect
    isolation_level=None, **self.connect_params)
peewee.OperationalError: unable to open database file

I am running prodigy custom recipe on linux and on intializing sqlite db , like custom database shows this error. It works with sudo but , I am using venv .

Hi! Can you share more about your setup? How are you setting up the database and are you sure the file it points to exists? This error happens in peewee, which Prodigy uses for its database connection and it indicates that there's something wrong with the SQLite file or file path. It might help to use peewee directly to test that you can connect to the DB.

db_folder = config.prodigy_database
db_path = db_folder + "/" + db_name + '.db'
sqlite_db = SqliteDatabase(db_path)
db = Database(sqlite_db, "sqlite", db_name)

This works fine in windows! Only when i try to run same thing on linux shows error!

That sounds like the problem may be related to the path formatting or file permissions?

1 Like