I am writing a script and having trouble even getting a basic one to work. Ghost seems to not be importing properly. I keep getting the following error:

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

Nothing special in the code:

 from ghost import Ghost
 ghost = Ghost()

I have PySide and PyQt both installed and I install Ghost by doing: sudo pip install ghost

有帮助吗?

解决方案

According to 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 is defined when at least one of PySide or PyQt4 is installed. Check you PySide, PyQt4(not PyQt5) installation using following import statement:

import PySide

import PyQt4

BTW, causing NameError instead of Exception with the message "Ghost.py requires PySide or PyQt4" is a bug. So I commented this.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top