我正在编写一个脚本,但连一个基本的脚本都无法运行。 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
最佳答案
...
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/