Pacharapol Withayasakpunt Pacharapol Withayasakpunt
Sat 27 January 2018
A successful py2app setup.py code

A successful py2app setup.py code

py2app and py2exe are how to compile a Python package bundle into a single file app. However, I had problem simply running py2applet --make-setup PatientLogbook.py database/user.db, so I have to edit the config file myself.

Root causes of the problem running python setup.py py2app include the following.

  • Misplaced data file, default not in the correct directory
  • passlib in py2app defaulted to using bcryptor instead of bcrypt
  • Even though I changed from passlib.hash import bcrypt to import bcrypt, I still need cffi for bcrypt to work

Here is a working setup.py.

"""
Usage:
python setup.py py2app
"""

from setuptools import setup

APP = ['PatientLogbook.py']
DATA_FILES = [
    ('database',['database/user.db'])
]
OPTIONS = {
    'includes': ['cffi'],
    'plist': {
        'CFBundleName': 'Patient Logbook'
    }
}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app','PyQt5','bcrypt','cffi'],
)