【问题标题】:binding is not defined while using Ghost.py使用 Ghost.py 时未定义绑定
【发布时间】:2013-12-29 03:40:42
【问题描述】:

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

【问题讨论】:

    标签: python pip ghost.py


    【解决方案1】:

    根据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")
    ...
    

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

    import PySide
    
    import PyQt4
    

    顺便说一句,导致NameError 而不是带有消息"Ghost.py requires PySide or PyQt4" 的异常是一个错误。所以I commented this

    【讨论】:

    • 所以导入 PySide 和 PyQt4 都不起作用。我使用自制软件安装了它们(例如 brew install pyqt)。我应该以另一种方式安装它们以使其正常工作吗?
    • @Zaheer,我不知道 homebrew。恕我直言,homebrewPyQt 安装到 python 实例 A,而 pip 将 Ghost.py 安装到实例 B。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-13
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    • 2021-10-27
    • 1970-01-01
    相关资源
    最近更新 更多