Sqlite3, OperationalError: unable to open database file

前端 未结 19 1634
再見小時候
再見小時候 2020-11-27 18:58

Question: Why can\'t I open the database?


Info: I\'m working on a project using sqlite3 database. I wrote a test program that runs and passes it t

19条回答
  •  萌比男神i
    2020-11-27 19:11

    In my case, the solution was to use an absolute path, to find an existing file:

    import os.path
    filepath = os.path.abspath(filepath)
    # Leave this out if the file doesn't exist yet
    assert os.path.exists(filepath), "The file doesn't exist"
    conn = sqlite3.connect(filepath)
    

    I don't know why this fix works: the path only contained ASCII characters and no spaces. Still it made the difference.

    For reference: Windows 7, Python 3.6.5 (64-bit).

    I was not able to reproduce the issue on another machine (also Windows 7, Python 3.6.4 64-bit), so I have no idea why this fix works.

提交回复
热议问题