Skip to content

The potential issues by pyinstaller packaging  #14

Description

@Tim-eyes

Context

Using pyinstaller to package multiple python files including self-defined dependences and model data file

Usage tool

pyinstaller

  1. Install or upgrade pyinstaller
pip install pyinstaller
pip install --upgrade pyinstaller
  1. Configure .spec in your root directory
pyinstaller -D <main script py file>

or

pyi-makespec -w <main script py file>
  1. Individual configuration
    How to implement the script file .spec :

    # -*- mode: python ; coding: utf-8 -*-
    
    
    block_cipher = None
    
    
    a = Analysis(['main.py','UI\\utils.py','UI\\menu.py','UI\\registration.py','showplot.py',
                    'sqlite3Helper.py','time_recorder.py','faceHelper.py','face_recognition\\api.py',
                    'menu_rc.py'],
                 pathex=['D:\\cs003-Face-cognition-Sign-In-System'],
                 binaries=[('D:\\python 3.9\\Lib\\site-packages\\face_recognition_models\\models\\*','face_recognition_models\\models')],
                 datas=[('D:\\python 3.9\\Lib\\site-packages\\face_recognition_models\\models\\*','face_recognition_models\\models')],
                 hiddenimports=['UI.menu', 'UI.registration', 'UI.utils', 'face_recognition.api',
                 'showplot','sqlite3Helper','time_recorder','faceHelper','menu_rc'],
                 hookspath=[],
                 hooksconfig={},
                 runtime_hooks=[],
                 excludes=[],
                 win_no_prefer_redirects=False,
                 win_private_assemblies=False,
                 cipher=block_cipher,
                 noarchive=False)
    pyz = PYZ(a.pure, a.zipped_data,
                 cipher=block_cipher)
    
    exe = EXE(pyz,
              a.scripts,
              a.binaries,
              a.zipfiles,
              a.datas,  
              [],
              name='face',
              debug=False,
              bootloader_ignore_signals=False,
              strip=False,
              upx=True,
              upx_exclude=[],
              runtime_tmpdir=None,
              console=True,
              disable_windowed_traceback=False,
              target_arch=None,
              codesign_identity=None,
              entitlements_file=None , icon='UI\\resources\\logo_round.ico')
    
    

    Pay attention to the arguments datas , binaries and hiddenimports in Analysis. If you use default configuration without adding these params or only input valid '.dat' in binaries, there are some errors :

    image

    or

    image

    Because the api.py uses the dlib to load model dataset in corresponding site-package

  2. Run .spec and generate build and dist directory in the root, the .exe file is in dist

    pyinstaller <your .spec file>
    

Release

version : v1.0-alpha

Reference

  1. https://stackoverflow.com/questions/42164910/pyinstaller-images-fail-to-extract
  2. pyinstaller face_recognition ageitgey/face_recognition#712
  3. https://stackoverflow.com/questions/63981999/runtime-error-unable-to-open-shape-predictor-68-face-landmark-dat-fail-to-exec

Metadata

Metadata

Assignees

No one assigned

    Labels

    tutorialtutorial for helping configuration

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions