ronaldoussoren / pyobjc

The Python <-> Objective-C Bridge with bindings for macOS frameworks
https://pyobjc.readthedocs.io
560 stars 47 forks source link

ImportError: cannot import name 'NSPoint' from 'AppKit._AppKit' #305

Closed yanone closed 4 years ago

yanone commented 4 years ago

Hellos,

I'm completely lost on this issue: It's from an app that's been packages with py2app and code signed as hardened runtime, with an entitlement for com.apple.security.cs.allow-unsigned-executable-memory.

Some classes import fine from AppKit, others don't. Of the below code, only the last line throws the error:

    from AppKit import NSApp
    from AppKit import NSObject, NSUserNotification, NSUserNotificationCenter, NSDistributedNotificationCenter
    from AppKit import NSView, NSToolbar
    from AppKit import NSPoint, NSSize, NSMakeRect

Traceback: ImportError: cannot import name 'NSPoint' from 'AppKit._AppKit' (/Users/yanone/Code/TypeWorldApp/dist/Type.World.app/Contents/Resources/lib/python3.7/AppKit/_AppKit.cpython-37m-darwin.so)

The same class imports fine outside of the .app, for instance in a normal Python shell. Any clues? Thank you!

yanone commented 4 years ago

Update: I just looked up that NSPoint is defined in the Foundation framework, but from Foundation import NSPoint fails as well in the .app bundle (and not otherwise) with ImportError: cannot import name 'NSPoint' from 'Foundation' (unknown location)

yanone commented 4 years ago

My bad, explicitly including the Foundation package in the py2app bundle solved the problem. I misinterpreted the traceback, thinking that Foundation is available, but NSPoint isn't, when actually the whole module wasn't accessible somewhere. Sorry for bothering, closing this.