Py2App not working when compiling app for distribution

Viewed 131

I have been trying to make my python program into an app so I can distribute it to other computers. I have tried using Py2App for this.

The program and GUI works perfectly when I run it after I make the app in Alias mode:

python setup.py py2app -A

However, when I make the app for distribution with the command:

python setup.py py2app

I get this text in red in the terminal at the very end:

Modules not found (conditional imports):
 * Cookie (requests.compat)
 * Image (/Users/Febin.J/Documents/Projects/Python Projects/Planner Builder/venv/lib/python3.8/site-packages/py2app/recipes/PIL/prescript.py)
 * Numeric (numpy.distutils.system_info)
 * OpenSSL.crypto (urllib3.contrib.pyopenssl)
 * PyQt6 (PIL.ImageQt)
 * PyQt6.QtGui (PIL.ImageQt)
 * PySide2 (PIL.ImageQt)
 * PySide2.QtGui (PIL.ImageQt)
 * PySide6 (PIL.ImageQt)
 * PySide6.QtGui (PIL.ImageQt)
 * Queue (urllib3.util.queue)
 * _manylinux (pkg_resources._vendor.packaging._manylinux)
 * _pytest (numpy.typing.tests.test_typing)
 * _ufunc (numpy.typing)
 * ccompiler_opt (numpy.distutils.tests.test_ccompiler_opt, numpy.distutils.tests.test_ccompiler_opt_conf)
 * cffi (PIL.ImageTk)
 * checks (numpy.core.tests.test_cython)
 * com (pkg_resources._vendor.appdirs)
 * com.sun.jna (pkg_resources._vendor.appdirs)
 * com.sun.jna.platform (pkg_resources._vendor.appdirs)
 * cookielib (requests.compat)
 * cryptography (requests)
 * cryptography.x509.extensions (urllib3.contrib.pyopenssl)
 * defusedxml (openpyxl.xml)
 * defusedxml.ElementTree (openpyxl.xml.functions)
 * lxml.etree (openpyxl.xml, openpyxl.xml.functions)
 * mem_policy (numpy.core.tests.test_mem_policy)
 * nose (numpy.testing._private.decorators, numpy.testing._private.utils, numpy.testing.tests.test_doctesting)
 * nose.plugins (numpy.testing._private.nosetester)
 * nose.plugins.builtin (numpy.testing._private.nosetester)
 * numarray (numpy.distutils.system_info)
 * numpy.testing.noseclasses ()
 * numpy_distutils (numpy.f2py.diagnose)
 * numpy_distutils.command.build_flib (numpy.f2py.diagnose)
 * numpy_distutils.command.cpuinfo (numpy.f2py.diagnose)
 * numpy_distutils.cpuinfo (numpy.f2py.diagnose)
 * numpy_distutils.fcompiler (numpy.f2py.diagnose)
 * pandas (xlwings.conversion.numpy_conv)
 * psutil._psutil_windows ()
 * pytest (numpy._pytesttester, numpy.testing._private.utils)
 * scipy (numpy.testing._private.nosetester)
 * test (multiprocessing.util)
 * urllib2 (requests.compat)
 * urlparse (requests.compat)
 * win32com.client (xlwings)
 * win32com.shell (pkg_resources._vendor.appdirs)
 * win32pdh (numpy.testing._private.utils)

When trying to open the app from Finder (going into the dist folder and double-clicking the .app) after this I get a message from Finder saying the app quit unexpectedly. When running from the terminal I get:

Abort trap: 6

I am using Python 3.8.9. I am using PyQt5 (v5.15) as my GUI and I am on a Mac (MacOS 12.1)

My setup.py file is this:

"""
This is a setup.py script generated by py2applet

Usage:
    python setup.py py2app
"""

from setuptools import setup

APP = ['mainwindow.py']
DATA_FILES = ["both_bins.png", "both_holidays.png", "green_bin.png", "s_holidays.png", "u_holidays.png", "important_dates.db"]
OPTIONS = {
    "iconfile":"logo.icns",
    "plist": {
        'CFBundleName': "Planner Builder",
        'CFBundleDisplayName': "Planner Builder",
        'CFBundleVersion': "1.1",
        'CFBundleShortVersionString': "1.1"
    }
}

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

Could you please help me solve this problem?

1 Answers

I am new to py2app and not an expert. Based on my limited experience, one thing to try, especially if the list of errors seems unrelated to your actual project, is to create the most minimal environment you need for your project, and then run py2app in that. For my project I started in a relatively bloated environment and got an endless stream of mysterious errors from py2app. When I started over with a minimal environment, it ran without a hitch.

Related