ronaldoussoren / pyobjc

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

Unable to import NS* classes from Cocoa/Appkit #211

Closed ronaldoussoren closed 7 years ago

ronaldoussoren commented 7 years ago

Original report by Anush Jayaraman (Bitbucket: anushjay, GitHub: anushjay).


Hello, I tried to use the searchKit example after installing pyobjc and my IDE is not able to resolve Cocoa.NSObject. Also, I'm unable to import NSworkspace from AppKit. Is this not supported anymore? Do I need to install any modules other than pyobjc? I'm fairly new to this and trying to write a simple app to work on Mac os sierra (10.12.16) (running latest pyobjc). Any suggestions would be helpful.

ronaldoussoren commented 7 years ago

Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).


Cocoa.NSObject is still supported and you don't have to install anything beyond "pip install pyobjc". I'm not sure what your problem is.

PyObjC does use a lazy initialisation for the framework wrappers (such as the Cocoa module), maybe that confuses your IDE.

ronaldoussoren commented 7 years ago

Original comment by Anush Jayaraman (Bitbucket: anushjay, GitHub: anushjay).


@ronaldoussoren Thanks for your response. I'm using pycharm. After importing Cocoa, my IDE throws an error saying Cannot find reference in init.py of Cocoa.NSobject.

Also pip install appkit gave an error which threw me off -- Collecting appkit Using cached AppKit-0.2.8.tar.gz Collecting flask (from appkit) Using cached Flask-0.12.2-py2.py3-none-any.whl Collecting pygobject (from appkit) Could not find a version that satisfies the requirement pygobject (from appkit) (from versions: ) No matching distribution found for pygobject (from appkit)

Let me try importing using an interpreter outside of the IDE.

ronaldoussoren commented 7 years ago

Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).


"pip install appkit" tries to install something that isn't part of PyObjC, "pip install pyobjc-framework-Cocoa" installs the AppKit bindings for PyObjC (although I'd just use "pip install pyobjc").

ronaldoussoren commented 7 years ago

Original comment by Anush Jayaraman (Bitbucket: anushjay, GitHub: anushjay).


Thank you. I think its just an issue with an IDE. I'm able to import Cocoa and use NSWorkspace and other required objects.

ronaldoussoren commented 7 years ago

Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).


Thanks. I've created issue #212 to look into the PyCharm issues (mostly be asking the pycharm folks if there's something I can do to avoid this problem)