3

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

Zaheer
  • 2,794
  • 5
  • 28
  • 33

1 Answers1

4

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.

falsetru
  • 357,413
  • 63
  • 732
  • 636
  • So both importing PySide and PyQt4 did not work. I installed them using homebrew (eg. brew install pyqt). It is there another way I should have installed them for it to work? – Zaheer Dec 29 '13 at 04:24
  • @Zaheer, I don't know about *homebrew*. IMHO, *homebrew* installed `PyQt` to python instance A, while *pip* installed Ghost.py to instance B. – falsetru Dec 29 '13 at 04:28