`ImportError: No module named AppKit` after installing AppKit and PyObjC

`ImportError: No module named AppKit` after installing AppKit and PyObjC

我正在尝试让一些 Python 代码在 Mac OS X Mojave with Python 2.7 上的 Anaconda 上进行全新安装。这是以前在同一台机器上工作的所有东西。

我得到的错误是:

Mac:~ kuzzooroo$ python
Python 2.7.15 |Anaconda, Inc.| (default, Dec 14 2018, 13:10:39)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import AppKit
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named AppKit

小写也不行:

>>> import appkit
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/kuzzooroo/anaconda2/lib/python2.7/site-packages/appkit/__init__.py", line 11, in <module>
    from AppKit import _metadata
ImportError: No module named AppKit

我进行了大量搜索,关于如何处理此错误的建议大多采用以下形式"make sure you've installed X."这是我得到的:

Mac:~ kuzzooroo$ brew install PyGObject PyGObject3
Warning: pygobject 2.28.7_1 is already installed and up-to-date
To reinstall 2.28.7_1, run `brew reinstall pygobject`
Warning: pygobject3 3.30.4 is already installed and up-to-date
To reinstall 3.30.4, run `brew reinstall pygobject3`
Mac:~ kuzzooroo$ pip install AppKit PyObjC PyObjC-core
Requirement already satisfied: AppKit in ./anaconda2/lib/python2.7/site-packages (0.2.8)
Requirement already satisfied: PyObjC in ./anaconda2/lib/python2.7/site-packages (5.1.2)
Requirement already satisfied: PyObjC-core in ./anaconda2/lib/python2.7/site-packages (5.1.2)
Requirement already satisfied: ... <many more lines>

brew install 步骤改变了错误,但如您所见,它们并没有给我留下有效的设置。

原来有人写了一个名为 AppKit 的包,它是完全不同的 Mac 操作系统组件。这是另一个 AppKit:

$ pip search appkit
AppKit (0.2.8)  - Desktop application framework based on Webkit HTML5, CSS3, Javascript and Python

除了 PyObjC 之外,安装它会产生冲突,导致出现无用的错误消息 No module named AppKit(实际上,运行 周围有两件事 运行)。

运行 conda uninstall AppKit 然后 pip install --upgrade --force-reinstall PyObjC PyObjC-core 解决了问题。