如何使用Python3 fbs软件包打包Sqlite3数据库?

时间:2019-10-01 06:20:05

标签: python macos sqlite pyqt5 fbs

我正在使用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应用程序,它就会拒绝查找或创建数据库。

1 个答案:

答案 0 :(得分:0)

已修复。如果有人遇到类似问题,请使用内置的appctxt.get_resource(file_path)方法。

相关问题