问题描述
我正在尝试使一些Python代码在Mac OS X Mojave上带有Python 2.7的Anaconda上的全新安装上工作.这些都是以前在同一台机器上工作的所有东西.
I'm trying to get some Python code working on a fresh installation on Anaconda on Mac OS X Mojave with Python 2.7. This was all stuff that was working before on the same machine.
我得到的错误是:
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
我已经做了很多搜索,有关如何处理此错误的建议大多采用确保已安装X"的形式.这就是我所拥有的:
I've done a lot of searching, and the suggestions for how to deal with this error are mostly of the form "make sure you've installed X." Here's what I've got:
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
步骤使错误有所不同,但是您可以看到它们并未使我无法正常工作.
The brew install
steps changed the error from something different, but as you can see they did not leave me with a working setup.
推荐答案
事实证明有人编写了一个名为AppKit的程序包,它是完全独立的Mac操作系统组件.这是另一个AppKit:
It turns out someone has written a package called AppKit that is completely distinct Mac operating system component. Here is the other AppKit:
$ pip search appkit
AppKit (0.2.8) - Desktop application framework based on Webkit HTML5, CSS3, Javascript and Python
除了安装PyObjC以外,安装该冲突还会导致产生无用的错误消息No module named AppKit
(实际上,使用此名称不是唯一的两件事).
Installing that in addition to PyObjC created a conflict that resulted in the unhelpful error message No module named AppKit
(in fact there were not one but two things running around with this name).
先运行conda uninstall AppKit
,然后再运行pip install --upgrade --force-reinstall PyObjC PyObjC-core
,即可解决问题.
Running conda uninstall AppKit
and then pip install --upgrade --force-reinstall PyObjC PyObjC-core
fixed the problem.
这篇关于`ImportError:安装AppKit和PyObjC之后,没有名为AppKit的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!