2013-04-05 61 views
4

我知道有類似的問題,但我找不到解決方案。這是我所做的。ImportError:無法導入名稱Ghost

我使用pip安裝了ghost模塊。 site-packages/ghost文件夾有3個文件__init__.py,ghost.pytest.py

__init__.py具有以下內容

from ghost import Ghost 
from test import GhostTestCase 

模塊認爲這種方法

from ghost import Ghost 

但它引發以下錯誤。

File "<pyshell#3>", line 1, in <module> 
    from ghost import ghost 
    File "G:\Python33\lib\site-packages\ghost\__init__.py", line 1, in <module> 
    from ghost import Ghost 
ImportError: cannot import name Ghost 

我試着將路徑添加到PYTHONPATH;它沒有工作。我想不通爲什麼它是一個標準的module.I發生在我工作的Python 3.3

+1

'ghost'模塊是你的模塊嗎?名稱之間可能存在衝突 – gipi 2013-04-05 16:33:59

+0

@gipi我沒有使模塊,我使用python模塊ghost – feminkk 2013-04-05 16:41:10

回答

6

使用Python 3,嘗試改變__init__.py該行

from .ghost import Ghost 

做包相對進口。如果可行,這是模塊中的一個錯誤,你應該report it

+0

的問題它的工作thanks.I將報告它 – feminkk 2013-04-05 16:53:20

-1

你做一個錯字請求

from ghost import ghost 

,而不是

from ghost import Ghost 

使得該模塊鬼嘗試導入「鬼」而不是「鬼」給出一個錯誤?

+0

感謝您的快速答覆。我檢查了模塊,但對象名稱是「鬼」本身..而不是「幽靈」。 – feminkk 2013-04-05 16:47:43

+0

我會嘗試在Python 3.3中安裝它,看看它是否會引發同樣的問題。 – Acebulf 2013-04-05 16:48:34

+0

我已經在python 3.3中了 – feminkk 2013-04-05 16:50:40

0

你是什麼pip命令行?應該pip install Ghost.py 而不是pip install ghost

0

我有同樣的問題,

如果腳本文件名爲ghost.pyGhost.py,你必須將它們重命名爲ghost以外的名稱。

之後,您必須刪除以前的腳本所創建的.pyc文件。

現在你可以運行你的代碼。

相關問題