How to include arm64 wheels into py2app generation?

46 Views Asked by At

I've been trying to get my python projects to work on arm64 OSX systems. I myself use an Intel Mac so I haven't been able to build it for arm64 yet. The problem is, as I realized, that the packages included all include an x86_64 arch and not an arm64 arch. I do use a venv to install all the packages and even tried some advice about how I could download the packages for other architectures, but now I'm stuck again, because I can only download the wheels for those packages as far as I know and I don't know how to include them and they aren't detected by py2app.

So here goes my question: How do I include the wheels properly, so it can run on arm64 OSX machines? Do I have to put them into the Contents folder separately or define their use somewhere in my setup file (which I haven't touched yet)?

Output when building:

checking for any import problems
Modules not found (unconditional imports):
 * PIL (/Users/<user>/Documents/Programming/python_projects/QRM/qrm_v1.0.py)
 * _io._WindowsConsoleIO (importlib._bootstrap_external)
 * _overlapped (asyncio.windows_events)
 * com (com.sun.jna)
 * com.jna (com.sun)
 * com.sun (com.sun.jna.platform)
 * customtkinter (/Users/<user>/Documents/Programming/python_projects/QRM/qrm_v1.0.py)
 * jinja2 (pkg_resources._vendor.pyparsing.diagram)
 * pyparsing (pkg_resources._vendor.pyparsing.diagram)
 * qrcode (/Users/<user>/Documents/Programming/python_projects/QRM/qrm_v1.0.py)
 * railroad (pkg_resources._vendor.pyparsing.diagram)
 * win32com (win32com)
 * win32com.shell (win32com.shell)
 * win32com.shellcon (win32com.shell)

Modules not found (conditional imports):
 * _manylinux (pkg_resources._vendor.packaging._manylinux)
 * com (pkg_resources._vendor.appdirs)
 * com.sun.jna (pkg_resources._vendor.appdirs)
 * com.sun.jna.platform (pkg_resources._vendor.appdirs)
 * win32com (pkg_resources._vendor.appdirs)
 * win32com.shell (pkg_resources._vendor.appdirs)

Done!

Output when launching the app on arm64 OSX, confirming the arch issues:

Traceback (most recent call last):
  File "/Users/username/Desktop/qrm_v1.0.app/Contents/Resources/__boot__.py", line 170, in <module>
    _run()
  File "/Users/username/Desktop/qrm_v1.0.app/Contents/Resources/__boot__.py", line 84, in _run
    exec(compile(source, path, "exec"), globals(), globals())
  File "/Users/username/Desktop/qrm_v1.0.app/Contents/Resources/qrm_v1.0.py", line 5, in <module>
    from PIL import Image
  File "PIL/Image.pyc", line 84, in <module>
  File "PIL/_imaging.pyc", line 14, in <module>
  File "PIL/_imaging.pyc", line 10, in __load
  File "imp.pyc", line 343, in load_dynamic
ImportError: dlopen(/Users/username/Desktop/qrm_v1.0.app/Contents/Resources/lib/python3.11/lib-dynload/PIL/_imaging.so, 0x0002): tried: '/Users/username/Desktop/qrm_v1.0.app/Contents/Resources/lib/python3.11/lib-dynload/PIL/_imaging.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/username/Desktop/qrm_v1.0.app/Contents/Resources/lib/python3.11/lib-dynload/PIL/_imaging.so' (no such file), '/Users/username/Desktop/qrm_v1.0.app/Contents/Resources/lib/python3.11/lib-dynload/PIL/_imaging.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
2024-02-13 13:19:32.840 qrm_v1.0[82739:1319035] Launch error
2024-02-13 13:19:32.840 qrm_v1.0[82739:1319035] Launch error
See the py2app website for debugging launch issues

The exact commands I used to build everything/get the arm64 wheels:

$ python3 -m venv env
$ . env/bin/activate
$ pip install py2app
$ python3 -m pip install --only-binary=:all: --platform macosx_11_0_arm64 Pillow
$ python3 -m pip install --only-binary=:all: --platform macosx_11_0_arm64 customtkinter
$ python3 -m pip install --only-binary=:all: --platform macosx_11_0_arm64 qrcode
$ py2applet --make-setup file.py
$ python setup.py py2app --arch arm64

The setup file:

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

Usage:
    python setup.py py2app
"""

from setuptools import setup

APP = ['/Users/<user>/Documents/Programming/python_projects/QRM/qrm_v1.0.py']
DATA_FILES = []
OPTIONS = {}

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

Edit: I also issued that on github as the documentation doesn't seem to have instructions on how to do this. https://github.com/ronaldoussoren/py2app/issues/520

0

There are 0 best solutions below