我正在使用FBS构建一个Python应用程序,但它的一部分依赖于SQLite3数据库。如果数据库找不到,我有代码来创建它,使用try-catch块。
当我尝试在编译后运行它时,它不仅找不到预先存在的SQLite3文件,而且也不会创建它。它不会显示任何错误消息。
如果文件不存在,我尝试使用以下代码创建该文件:
try:
self.connection = sqlite3.connect(path)
self.cursor = self.connection.cursor()
except:
if not os.path.exists(path):
# Try and make the .config directory
try:
os.makedirs(".config")
except OSError as e:
if e.errno != errno.EEXIST:
raise
# Create the datastore, and close it
f = open(path, "w+")
f.close()
# And try connect to database again
return self.__connect(path)
else:
print(f"No database exists, and could not create one.\nPlease create file in app directory called: {path}\nThen restart application.")
raise代码可以在dev中查找,但一旦我将其编译成Mac应用程序,它就拒绝查找或创建数据库。
发布于 2019-10-01 14:41:30
已修复。如果任何人有类似的问题,请使用内置的appctxt.get_resource(file_path)方法。
https://stackoverflow.com/questions/58179054
复制相似问题