Is it possible to use Cocoa API with Python?

a 夏天 提交于 2020-05-14 08:50:11

问题


I was wondering if it is possible to use Cocoa (Apple's API) with Python, so being able to run any code like in this link, so NSWorkspace functions and so on, this might be a super stupid question, but I was still wondering if it was possible...


回答1:


Yes.

There are Python packages, kind of wrappers around Objective-C, install them like:

$ pip install pyobjc-core
$ pip pyobjc-framework-Cocoa
$ pip pyobjc-framework-Quartz

https://pypi.org/project/pyobjc-framework-Cocoa/




回答2:


MacOS by default comes with python 2.7 and pyObjC 2.5, and has done for years. If you want a newer version of either python, such as python 3, or the newest version of pyObjC, then you have to install it yourself.

The latest version of pyObjC is 5.2.

However, on a default installation of MacOS from at least Snow Leopard onward, the following should work:

python
   >>> import Appkit
   >>> AppKit.NSWorkspace.sharedWorkspace().runningApplications()

Catalina is stated to be the last version to contain python bundled.



来源:https://stackoverflow.com/questions/57459691/is-it-possible-to-use-cocoa-api-with-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!