使用Ghost.py时未定义绑定

时间:2013-12-29 03:40:42

标签: python pip ghost.py

我正在编写一个脚本,甚至无法使基本的脚本工作。 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

1 个答案:

答案 0 :(得分:4)

根据the Ghost.py source code

...
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")
...
安装PySide或PyQt4中的至少一个时定义

binding。使用以下import语句检查PySide,PyQt4(而不是PyQt5)安装:

import PySide

import PyQt4

BTW,导致NameError而不是Exception,消息"Ghost.py requires PySide or PyQt4"是一个错误。所以I commented this