3

我正在编写一个脚本,甚至无法让一个基本的脚本正常工作。Ghost 似乎没有正确导入。我不断收到以下错误:

>>>from ghost import Ghost
  File "/Library/Python/2.7/site-packages/ghost/__init__.py", line 1, in <module>
from .ghost import Ghost, Error, TimeoutError
  File "/Library/Python/2.7/site-packages/ghost/ghost.py", line 23, in <module>
    if binding is None:
NameError: name 'binding' is not defined

代码中没有什么特别之处:

 from ghost import Ghost
 ghost = Ghost()

我已经安装了 PySide 和 PyQt,我通过以下方式安装了 Ghost: sudo pip install ghost

4

1 回答 1

4

根据Ghost.py 源代码

...
bindings = ["PySide", "PyQt4"]

for name in bindings:
    try:
        binding = __import__(name)
        break
    except ImportError:
        continue


if binding is None:
    raise Exception("Ghost.py requires PySide or PyQt4")
...

binding至少在安装 PySide 或 PyQt4 之一时定义。import使用以下语句检查您的 PySide、PyQt4(不是 PyQt5)安装:

import PySide

import PyQt4

顺便说一句,导致NameError消息而不是异常"Ghost.py requires PySide or PyQt4"是一个错误。所以我评论了这个

于 2013-12-29T03:44:39.657 回答