python - 使用 Ghost.py 时未定义绑定(bind)

标签 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

最佳答案

根据 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" 的 Exception 是一个错误。所以I commented this .

关于python - 使用 Ghost.py 时未定义绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20821914/

相关文章:

python - Tornado Web 服务器与 AngularJS 运算符表达式一起工作时效果不佳

python - pip install web3 未安装

python - python Ghost.py不支持的字段标签错误

Python.exe appcrash 与 Ghost.py

javascript - 为什么 Ghost.py 不加载/运行我的 Javascript?

python - 使用 Python 请求的异步请求

python - 在 Python 中列出 JSON 字段

python - 在 Python 中检索浏览器 header

pip - 如何在 windows 上的 python 3.4 版本中安装 requests 模块?

python - 为什么 "pip install"在 setup.py 中引发语法错误?