Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

py2app doesn't include all external libraries for distribution #520

Open
blank-ctrl opened this issue Feb 10, 2024 · 3 comments
Open

py2app doesn't include all external libraries for distribution #520

blank-ctrl opened this issue Feb 10, 2024 · 3 comments

Comments

@blank-ctrl
Copy link

I've tried to create simple gui apps with py2app. Generally everything works fine on my machine which is an Intel Mac. Using the standard libraries with tkinter, filedialoge and collections everything works fine when distributed too. Yet when adding external libraries such as customtkinter, qrdcode, PIL and segno, the apps crash. I've searched for solutions for a long time and none of the flags in the documentation where of any help. I left my setup.py untouched and only added packages through the command line in case py2app didnt catch them. Still it didn't work. I noticed that some imports failed in the building process and think the problem may lay within those.

checking for any import problems
Modules not found (unconditional imports):
 * Foundation (darkdetect._mac_detect)
 * IPython (PIL.ImageShow)
 * PyObjCTools (darkdetect._mac_detect)
 * PyQt6.QBuffer (PyQt6.QtCore, PyQt6.QtGui)
 * PyQt6.QIODevice (PyQt6.QtCore, PyQt6.QtGui)
 * PySide6.QBuffer (PySide6.QtCore, PySide6.QtGui)
 * PySide6.QIODevice (PySide6.QtCore, PySide6.QtGui)
 * _io._WindowsConsoleIO (importlib._bootstrap_external)
 * _overlapped (asyncio.windows_events)
 * cffi (PIL.Image, PIL.PyAccess)
 * cffi.FFI (PIL.Image)
 * com (com.sun.jna)
 * com.jna (com.sun)
 * com.sun (com.sun.jna.platform)
 * defusedxml (PIL.Image)
 * jinja2 (pkg_resources._vendor.pyparsing.diagram)
 * pyparsing (pkg_resources._vendor.pyparsing.diagram)
 * railroad (pkg_resources._vendor.pyparsing.diagram)
 * win32com (win32com)
 * win32com.shell (win32com.shell)
 * win32com.shellcon (win32com.shell)

Modules not found (conditional imports):
 * Image (/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/py2app/recipes/PIL/prescript.py)
 * PyQt6 (PIL.ImageQt)
 * PyQt6.QtGui (PIL.ImageQt)
 * PySide6 (PIL.ImageQt)
 * PySide6.QtGui (PIL.ImageQt)
 * _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)

Until today I have only distributed to another Silicon Mac (defining the right building arch and all that yada yada). And as said before. Standard libraries work fine, those installed through pip do not.

I'm not sure if there's a solution to this, but it's been 2 and a half months now that I've been looking for a solution and this is pretty much the last clue I have as to what might have gone wrong.

@blank-ctrl
Copy link
Author

blank-ctrl commented Feb 12, 2024

For the record, I now also tried to install the packages in a python venv and the same problems occured. Also, installing packages for arm64 did not work by declaring it in the command line with „arch -arm64 …“.

@blank-ctrl
Copy link
Author

blank-ctrl commented Feb 13, 2024

It is indeed an import error due to arm64 not being included in the packages installed.

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

So yeah, I guess I‘m close to figuring out how to make it distributable to arm64, but I have not yet found a way to install a arm64 package on an x86_64 device even with a VEnv.

@blank-ctrl
Copy link
Author

After some digging I tried again.

$ 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

I don't know how to include the .whl into the process and haven't found something yet that provides help with correctly including them, so the app can run on arm64 as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant