3

Hello stackoverflow community once again. I have yet another question.

Recently, I've found a python library that looked rather useful to me for a recent project by the name of Ghost.py. This library is a net library.

The issue I'm having is a rather strange error. Google is turning up nothing relevant.

from .ghost import Ghost
SystemError: Parent module '' not loaded, cannot perform relative import

As you can see, it's a rather odd error. Any help on solving this error is appreciated, thanks.

NAME__
  • 625
  • 1
  • 7
  • 17
  • What do you mean by "_net library_"? Did you mean that you are using IronPython and this is a .Net library? Also, could you share that library? Also, why the relative import? Shouldn't `from ghost import Ghost` be enough? Or maybe it is an error within that library? – Tadeck Jul 15 '13 at 02:26
  • By net library, I mean a library for running JavaScript and HTTP statement. It could be an error within that library, but I haven't managed to find another library of its type that can use JavaScript on web-pages. – NAME__ Jul 15 '13 at 02:38
  • I got the same error with `pip install ghost.py`. When I installed manually using the zip from github, everything worked great. If you haven't got it working already, give that a try. – midrare Aug 02 '13 at 08:35

3 Answers3

3

+1 for Babby Boss as his/her solution will work however I was lazy and I came here when I also had the issue and my problem was fixed by by me uninstalling Ghost which I had installed like the OP using pip and instead installing Ghost.py

Note that Ghost and Ghost.py are not the same, and using pip to install Ghost will cause an error if, like me, you wanted Ghost.py

So simple fix =
pip2 uninstall Ghost (wait for this to complete)
pip2 install Ghost.py

SherylHohman
  • 16,580
  • 17
  • 88
  • 94
2

You have an extra . in front of ghost. I don't think you need it:

from ghost import Ghost
jh314
  • 27,144
  • 16
  • 62
  • 82
  • It depends on where it is located (if this line is in external library, then the issue is not OP's error seemingly). – Tadeck Jul 15 '13 at 02:27
  • Without it I am granted with another error, hence why I put it there in the first place. It was suggested to do so in an old thread I found about error number one. Removing it gives me this error:ImportError: cannot import name Ghost – NAME__ Jul 15 '13 at 02:27
  • How did you install it? – jh314 Jul 15 '13 at 02:29
0

Apart from writing correct code like from ghost import Ghost, you may like to follow steps outlined below.

Download ghost.py master file from https://github.com/jeanphix/Ghost.py/archive/master.zip

Unzip contents of master.zip to C:\ghost-master folder

If you carefully watch the folder structure then you find that ghost\__init__.py file has following content.

from .ghost import Ghost, Error, TimeoutError
from .test import GhostTestCase

While ghost\ext\__init__.py is of 0 KB

In this case, when you run following command to build the package.

C:\<path_to_Python_folder>\python.exe setup.py build

you see that apart from other lines, following line also appears.

copying ghost\ext\__init__.py -> build\lib\ghost\ext

It means that __init__.py of 0 KB size is being copied as build\lib\ghost\ext\__init__.py

Therefore, even though installing ghost.py with following command does not produce any error, you face ImportError: cannot import name Ghost.

C:\<path_to_Python_folder>\python.exe setup.py install

So, to solve the problem, before building the package overwrite __init__.py file

C:\ghost-master>copy ghost\__init__.py ghost\ext\   

Now issue following commands.

C:\<path_to_Python_folder>\python.exe setup.py build
C:\<path_to_Python_folder>\python.exe setup.py install

Now you will not see ImportError: cannot import name Ghost

I have tested above solution with Python 2.7.6