sqlite + PyQt5 to standalone exe - Python 3.6.3 + Pyinstaller

后端 未结 1 1040
醉酒成梦
醉酒成梦 2021-01-16 01:36

I would like to create an exe with Pyinstaller including a database (.db) and a picture (.png). I want everything into a single

相关标签:
1条回答
  • 2021-01-16 02:18

    You have to solve many issues to get this working. For example:

    • Getting the right resource path
    • Adding data

    The first issue is solved by adjusting paths depending on execution mode.

    def app_path(path):
        frozen = 'not'
        if getattr(sys, 'frozen', False):
                # we are running in executable mode
                frozen = 'ever so'
                app_dir = sys._MEIPASS
        else:
                # we are running in a normal Python environment
                app_dir = os.path.dirname(os.path.abspath(__file__))
        return os.path.join(app_dir, path)
    

    The second issue is efficiently including what you need. At first the obvious solution is to add each image and db manually, but i had lots of image. I turned to the spec file way using the wildcard operator (*) to add what i need in folder than adding folder/*.

    added_files = [
             ( './pics/*', 'pics' ),
             ( './db/*', 'db' ),
             ]
    

    then in Analysis,

    datas = added_files
    

    A thorough answer is quite long. I've written this article to show in some minute details what i went through to solve the issue.

    0 讨论(0)
提交回复
热议问题