flask pyinstaller executable unable to create/read SQLite3 database

I’ve created a flask executable using pyinstaller. The app has to read and write to a SQLite3 database. I am using flask-sqlalchemy and flask-migrate, flaskwebgui for opening in browser. The executable is unable to read the database.

Details:
Using the following spec file to create a standalone exe file

# -*- mode: python ; coding: utf-8 -*-

added_files = [
    ('main/templates/', 'templates'),
    ('main/static/', 'static')  
]

a = Analysis(
    ['run.py'],
    pathex=[],
    binaries=[],
    datas=added_files,
    hiddenimports=[],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    noarchive=False,
    optimize=0,
)
pyz = PYZ(a.pure)

exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.datas,
    [],
    name='run',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    upx_exclude=[],
    runtime_tmpdir=None,
    console=False,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
)

  • The resulting /dist folder has an executable called run.exe. I am able to run the exe which opens a browser window (using Flaskwebgui) and the index page loads normally but as soon as I try to open ‘all loans’ view it gives error
    sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: loan.
  • The flask app is able to read/write to the database when run normally (command line) but it give error when running from the executable.
  • In the root directory, the database file called loansdb is stored inside /instance directory which was created by flask-migrate.
  • folder structure (overview only, not exact)
project/
  |- main/
    |- routes.py
    |- __init__.py
    |- models.py
    |- templates/
       |- index.html
    |- static/
       |- style.css
  |- dist/
    |- run.exe
    |- logs/
  |- instance/
    |- loansdb

  • The app reads the environment variables for the DATABASE_URL and I have verified that the executable is also able to read the environment variables.
  • I put the loansdb file in the /dist folder like:
project
   |- dist
     |- run.exe
     |- loansdb

but it did not fix the problem.

  • Similar to the above method, I put the whole /instance folder inside /dist but that also had no effect.
  • I read up on this article talking about copying the temp files into the application’s directory but neither do I understand half of it and nor does it work.

Expected Behavior

  • My understanding is that the database cannot be a part of the executable because that will make the database read-only because it runs in a ‘frozen’ state, which is not desired in this case.
  • Being able to ship the program as a zip with the executable, database and other files such as a manual/readme would be most optimal for my use case.
  • I am fairly new to flask and sqlalchemy and I would appreciate any alternative approach as well.

New contributor

JuveWatson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật