のような正しいコードを書くこととは別に、from ghost import Ghost
以下に概説する手順に従うことをお勧めします。
https://github.com/jeanphix/Ghost.py/archive/master.zipghost.py
からマスター ファイルをダウンロードします。
master.zip
toC:\ghost-master
フォルダの中身を解凍
フォルダ構造を注意深く見ると、ghost\__init__.py
ファイルには次の内容が含まれていることがわかります。
from .ghost import Ghost, Error, TimeoutError
from .test import GhostTestCase
がghost\ext\__init__.py
0 KB の場合
この場合、次のコマンドを実行してパッケージをビルドします。
C:\<path_to_Python_folder>\python.exe setup.py build
他の行とは別に、次の行も表示されていることがわかります。
copying ghost\ext\__init__.py -> build\lib\ghost\ext
これは__init__.py
、0 KB のサイズが次のようにコピーされていることを意味します。build\lib\ghost\ext\__init__.py
したがって、次のコマンドで Ghost.py をインストールしてもエラーは発生しませんが、ImportError: cannot import name Ghost
.
C:\<path_to_Python_folder>\python.exe setup.py install
そこで、問題を解決するために、パッケージの上書き__init__.py
ファイルをビルドする前に
C:\ghost-master>copy ghost\__init__.py ghost\ext\
次のコマンドを発行します。
C:\<path_to_Python_folder>\python.exe setup.py build
C:\<path_to_Python_folder>\python.exe setup.py install
今、あなたは見えませんImportError: cannot import name Ghost
上記のソリューションをPython 2.7.6でテストしました