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

p2App: MTLIOAccelDevice bad MetalPluginClassName property (null) on app startup #359

Closed
dequeb opened this issue Jul 6, 2021 · 5 comments

Comments

@dequeb
Copy link

dequeb commented Jul 6, 2021

I'm using python 3.9 to compile a simple Qt6 "Hello World" application in Cython and py2app. It works perfectly fine under CPython 3.9. It compiles properly but fails to run in Cython and p2app.

Here are the project files:

testLoad.pyx:

import sys
from PyQt6.QtWidgets import QMessageBox, QApplication

def main():
    app = QApplication(sys.argv)
    QMessageBox(text="Hello World").exec()

if __name__ == "__main__":
    main()

main.py:

import testLoad
from logging import basicConfig

def main():
    testLoad.main()

if __name__ == '__main__':
    main()

and setup.py:

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

from setuptools import setup
from Cython.Build import cythonize
from Cython.Distutils import build_ext


setup(
    name='test',
    # Include additional files into the package using MANIFEST.in
    include_package_data=True,
    app= ['__main__.py'],
    data_files=[],
    cmdclass = {'build_ext': build_ext},
    ext_modules = cythonize(["testLoad.pyx"], language_level=3),

    setup_requires=['py2app'],
    options={
             'cython': {"language_level":"3"}
            },
    install_requires=[
        "Cython"
    ],
    entry_points={
        "console_scripts": [
            "testLoad = __main__:main"
        ]
    },
)

When I run the program, I get this error on the console:

erreur  17:04:44.035551-0400    test    MTLIOAccelDevice bad MetalPluginClassName property (null)
erreur  17:04:44.047081-0400    test    +[MTLIOAccelDevice registerDevices]: Zero Metal services found
@dequeb
Copy link
Author

dequeb commented Jul 6, 2021

See related issue at: cython/cython#4269

@dequeb
Copy link
Author

dequeb commented Jul 6, 2021

The application runs fines from CPython form main.py with only testLoad.pyx compiled. Clearly an issue with packaging by py2app.

@ronaldoussoren
Copy link
Owner

One thing that will be problematic here is that testLoad.pyx is an extension and as such cannot be inspected by the module graph builder. If this is module is the only one using PyQt that library won't be added to the generated app bundle.

The best workaround for that is to have add an import of PyQt to one of the pure python modules. Adding a "packages" option likely won't work because PyQt requires some special handling in py2app.

That said, I haven't tested this workaround yet.

@ronaldoussoren
Copy link
Owner

The error message I get:

% dist/test.app/Contents/MacOS/test                                                                                                                                                                                                         (master)py2app
Traceback (most recent call last):
  File "/Users/ronald/Projects/py2app/examples/PyQt/cython_app/dist/test.app/Contents/Resources/__boot__.py", line 118, in <module>
    _run()
  File "/Users/ronald/Projects/py2app/examples/PyQt/cython_app/dist/test.app/Contents/Resources/__boot__.py", line 84, in _run
    exec(compile(source, path, "exec"), globals(), globals())
  File "/Users/ronald/Projects/py2app/examples/PyQt/cython_app/dist/test.app/Contents/Resources/main.py", line 1, in <module>
    import testLoad
  File "testLoad.pyx", line 2, in init testLoad
ModuleNotFoundError: No module named 'PyQt6'
2021-08-29 11:10:46.581 test[2231:3631548] test Error

Adding a dummy function to main.py fixes that problem:

def deps():
    from PyQt6.QtWidgets import QMessageBox, QApplication

Alternatively add an option to setup.py to tell py2app to include PyQt:

setup(
    ...,
    options={
             'cython': {"language_level":"3"},
             'py2app': {"includes": "PyQt6.QWidget"}
            },
    ...
)

That doesn't fix all problems though, I now get a different error:

Traceback (most recent call last):
  File "/Users/ronald/Projects/py2app/examples/PyQt/cython_app/dist/test.app/Contents/Resources/__boot__.py", line 118, in <module>
    _run()
  File "/Users/ronald/Projects/py2app/examples/PyQt/cython_app/dist/test.app/Contents/Resources/__boot__.py", line 84, in _run
    exec(compile(source, path, "exec"), globals(), globals())
  File "/Users/ronald/Projects/py2app/examples/PyQt/cython_app/dist/test.app/Contents/Resources/main.py", line 1, in <module>
    import testLoad
  File "testLoad.pyx", line 2, in init testLoad
  File "<frozen zipimport>", line 259, in load_module
  File "PyQt6/QtWidgets.pyc", line 14, in <module>
  File "PyQt6/QtWidgets.pyc", line 10, in __load
  File "imp.pyc", line 342, in load_dynamic
ImportError: dlopen(/Users/ronald/Projects/py2app/examples/PyQt/cython_app/dist/test.app/Contents/Resources/lib/python3.9/lib-dynload/PyQt6/QtWidgets.so, 2): Library not loaded: @rpath/QtWidgets.framework/Versions/A/QtWidgets
  Referenced from: /Users/ronald/Projects/py2app/examples/PyQt/cython_app/dist/test.app/Contents/Resources/lib/python3.9/lib-dynload/PyQt6/QtWidgets.so
  Reason: image not found
2021-08-29 11:11:59.499 test[2369:3633301] test Error

That's a different problem: PyQt6 requires a recipe update. Using PyQt5 instead of PyQt6 results in a working application.

ronaldoussoren added a commit that referenced this issue Aug 29, 2021
This example is used to debug #359
ronaldoussoren added a commit that referenced this issue Aug 29, 2021
ronaldoussoren added a commit that referenced this issue Aug 29, 2021
ronaldoussoren added a commit that referenced this issue Aug 29, 2021
@ronaldoussoren
Copy link
Owner

  • Documented workaround in this issue
  • Added a FAQ entry about using Cython with py2app
  • Added recipe for PyQ6

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

2 participants