1

My flask app is unable to open a db when I use it's relative path:

conn = sqlite3.connect("down.db")

It works fine I use the absolute path:

conn = sqlite3.connect("C:\\Users\\Lenovo\\PycharmProjects\\spacedonline\\down.db")

I've tried using .\ as well. Any help would be appreciated.

  • What is the output of `os.getcwd()`, and does this match the directory of the database? That aside, explicit paths are a safe bet. – S3DEV Dec 23 '21 at 14:18

1 Answers1

1

Assuming the file is in the same directory as the app, you could do something like

import os

path = os.path.dirname(os.path.realpath(__file__)) # directory path of the app
conn = sqlite3.connect(path+"/down.db")

# or - after @S3DEV comment
conn = sqlite3.connect(os.path.join(path, "down.db"))