PyObjC assert error when running macOS app that uses pynput
See original GitHub issueI’m using Python 3.10.4 (from python.org) on macOS Monterey.
I created a virtual environment with python -m venv env
and activated it
Then I installed:
pip install nuitka
pip install pynput
Here is what pip installed:
Package Version
------------------------------------ -------
Nuitka 0.8.3
pip 22.0.4
pynput 1.7.6
pyobjc-core 8.5
pyobjc-framework-ApplicationServices 8.5
pyobjc-framework-Cocoa 8.5
pyobjc-framework-Quartz 8.5
setuptools 58.1.0
six 1.16.0
I created main.py with this code:
import pynput
print("hello")
The program works and prints “hello”
Then I run this command:
python -m nuitka --follow-imports --standalone main.py --output-dir=publish
Output:
Nuitka-Options:INFO: Used command line options: --follow-imports --standalone main.py --output-dir=publish
Nuitka-Options:INFO: Following all imports is the default for standalone mode and need not be specified.
Nuitka:WARNING: Using very slow fallback for ordered sets, please install
Nuitka:WARNING: 'ordered-set' or 'orderset' PyPI packages for best Python
Nuitka:WARNING: compile time performance.
Nuitka:INFO: Starting Python compilation with Nuitka '0.8.3' on Python '3.10' commercial None.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'pynput.mouse' added 'pynput.mouse._darwin'.
Nuitka-Plugins:INFO: anti-bloat: Handling module 'pkg_resources' with 1 change(s) for: avoid using plistlib dependency on non-macOS.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'pkg_resources.extern' added 'pkg_resources._vendor.packaging,pkg_resources._vendor.pyparsing,pkg_resources._vendor.appdirs'.
Nuitka-Plugins:INFO: anti-bloat: Handling module 'pydoc' with 1 change(s) for: remove module ability to display GUI with tkinter and topics data.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'pkg_resources._vendor.packaging' added 'pkg_resources._vendor.packaging.version,pkg_resources._vendor.packaging.specifiers,pkg_resources._vendor.packaging.requirements'.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'pynput.keyboard' added 'pynput.keyboard._darwin'.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'zipfile' added 'py_compile'.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'urllib.request' added 'http.client,http.cookiejar'.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'socket' added '_socket'.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'shelve' added 'dbm.dumb'.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'pathlib' added 'ntpath,posixpath'.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'importlib.metadata' added 'email'.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'ctypes' added '_ctypes'.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module '_asyncio' added 'asyncio'.
Nuitka-Plugins:INFO: implicit-imports: Implicit dependencies of module 'encodings' added 'encodings.idna,encodings.base64_codec,encodings.hex_codec,encodings.rot_13'.
Nuitka:INFO: Completed Python level compilation and optimization.
Nuitka:INFO: Generating source code for C backend compiler.
Nuitka:INFO: Running data composer tool for optimal constant value handling.
Nuitka:INFO: Running C compilation via Scons.
Nuitka-Scons:INFO: Backend C compiler: clang (clang).
Nuitka will make use of ccache to speed up repeated compilation.
Is it OK to download and put it in '/Users/hsc/Library/Application Support/Nuitka/ccache/v4.2.1'.
No installer needed, cached, one time question.
Proceed and download? [Yes]/No
n
Nuitka-Scons:INFO: Slow C compilation detected, used 60s so far, scalability problem.
Nuitka-Scons:INFO: Running clang -o module.AppKit._metadata.o -c -std=c11 -fvisibility=hidden -fwrapv -pipe -w -fvisibility=hidden -fvisibility-inlines-hidden --target=x86_64-apple-macos10.9 -O3 -D_XOPEN_SOURCE -D__NUITKA_NO_ASSERT__ -D_NUITKA_STANDALONE -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=151 -D_NUITKA_EXE -I/Library/Frameworks/Python.framework/Versions/3.10/include/python3.10 -I. -I/Users/hsc/dev/globalhotkeys/env/lib/python3.10/site-packages/nuitka/build/include -I/Users/hsc/dev/globalhotkeys/env/lib/python3.10/site-packages/nuitka/build/static_src module.AppKit._metadata.c took 144.08 seconds
Nuitka-Scons:INFO: Backend linking program (no progress information available).
Nuitka-Scons:WARNING: You are not using ccache.
Nuitka:INFO: Keeping build directory 'publish/main.build'.
Nuitka:INFO: Created binary that runs on macOS 10.9 (x86_64) or higher.
Nuitka:INFO: Successfully created 'publish/main.dist/main'.
The binary was created succesfully but when I run the programm, I get this error:
(env) globalhotkeys $ ./publish/main.dist/main
Traceback (most recent call last):
File "/Users/hsc/dev/globalhotkeys/publish/main.dist/main.py", line 1, in <module>
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "/Users/hsc/dev/globalhotkeys/publish/main.dist/pynput/__init__.py", line 40, in <module pynput>
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "/Users/hsc/dev/globalhotkeys/publish/main.dist/pynput/keyboard/__init__.py", line 31, in <module pynput.keyboard>
File "/Users/hsc/dev/globalhotkeys/publish/main.dist/pynput/_util/__init__.py", line 70, in backend
File "importlib.py", line 126, in import_module
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "/Users/hsc/dev/globalhotkeys/publish/main.dist/pynput/keyboard/_darwin.py", line 29, in <module pynput.keyboard._darwin>
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "/Users/hsc/dev/globalhotkeys/publish/main.dist/Quartz/__init__.py", line 6, in <module Quartz>
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "/Users/hsc/dev/globalhotkeys/publish/main.dist/AppKit/__init__.py", line 10, in <module AppKit>
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "/Users/hsc/dev/globalhotkeys/publish/main.dist/Foundation/__init__.py", line 9, in <module Foundation>
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "/Users/hsc/dev/globalhotkeys/publish/main.dist/CoreFoundation/__init__.py", line 13, in <module CoreFoundation>
File "/Users/hsc/dev/globalhotkeys/publish/main.dist/objc/_lazyimport.py", line 152, in __init__
File "/Users/hsc/dev/globalhotkeys/publish/main.dist/objc/_lazyimport.py", line 510, in __load_cftypes
objc.internal_error: PyObjC: internal error in PyObjCClass_UnbuildClass at Modules/objc/class-builder.m:104: assertion failed: objc_class != nil
I have never tried this with older versions of Nuitka so I do not know if this is a regression.
Issue Analytics
- State:
- Created a year ago
- Comments:11 (9 by maintainers)
Top Results From Across the Web
Error installing Pyobjc on macOS 11.0 Big Sur - Stack Overflow
I believe the issue should be resolved by now. So running pip install pyobjc should be working again as expected (tested for pyobjc-7.0.1 ......
Read more >pynput - Python Package Health Analysis - Snyk
Ensure you're using the healthiest python packages. Snyk scans all the packages in your projects for vulnerabilities and provides automated fix advice.
Read more >conda-forge feedstocks | community driven packaging for conda
... pyobis: pyobis-feedstock · pyobjc-framework-fsevents: pyobjc-framework-fsevents-feedstock · pyout: pyout-feedstock · pyorc: pyorc-feedstock ...
Read more >How to Make Hotkeys in Python - Nitratine
I'm trying to convert a Python script which uses pynput into an exe using auto-py-to-exe. However, it raises an ImportError when executed. This ......
Read more >nuitka Changelog - pyup.io
Nuitka asserted against it failing, where some code handles it ... macOS: Catch user error of disabling the console without using the
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This issue can be narrowed down to just
pyobjc
and the following reproducer:@emre84 isn’t is clear that posting new issues below other issues is not getting accepted?