2017-07-26 62 views
2

我有一個在我的VCS託管的包裝。我運行:皮普列表顯示包安裝,但進口包拋出導入錯誤

$ pip install -vvv git+https://myvcs.com/myprotos 

這裏是日誌。你會注意到它運行在安裝中間實際上建立在項目源文件自定義腳本。請參閱this question for details of what it's doing

Collecting git+https://myvcs.com/myprotos 
    Cloning https://myvcs.com/myprotos to /private/var/folders/3t/4qwkfyr903d0b7db7by2kj6r0000gn/T/pip-cFzP3I-build 
    Running command git clone -q https://myvcs.com/myprotos /private/var/folders/3t/4qwkfyr903d0b7db7by2kj6r0000gn/T/pip-cFzP3I-build 
    Running setup.py (path:/private/var/folders/3t/4qwkfyr903d0b7db7by2kj6r0000gn/T/pip-cFzP3I-build/setup.py) egg_info for package from git+https://myvcs.com/myprotos 
    Running command python setup.py egg_info 
    running egg_info 
    creating pip-egg-info/myprotos.egg-info 
    writing pip-egg-info/myprotos.egg-info/PKG-INFO 
    writing top-level names to pip-egg-info/myprotos.egg-info/top_level.txt 
    writing dependency_links to pip-egg-info/myprotos.egg-info/dependency_links.txt 
    writing manifest file 'pip-egg-info/myprotos.egg-info/SOURCES.txt' 
    reading manifest file 'pip-egg-info/myprotos.egg-info/SOURCES.txt' 
    writing manifest file 'pip-egg-info/myprotos.egg-info/SOURCES.txt' 
    Source in /private/var/folders/3t/4qwkfyr903d0b7db7by2kj6r0000gn/T/pip-cFzP3I-build has version 0.0.1, which satisfies requirement myprotos==0.0.1 from git+https://myvcs.com/myprotos 
Installing collected packages: myprotos 
    Running setup.py install for myprotos: started 
    Running command /usr/local/opt/python/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/3t/4qwkfyr903d0b7db7by2kj6r0000gn/T/pip-cFzP3I-build/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /var/folders/3t/4qwkfyr903d0b7db7by2kj6r0000gn/T/pip-M03grb-record/install-record.txt --single-version-externally-managed --compile 
    running install 
    Grabbing github.com/google/protobuf... 
    Building Python protos... 
    running build 
    running install_egg_info 
    running egg_info 
    creating myprotos.egg-info 
    writing myprotos.egg-info/PKG-INFO 
    writing top-level names to myprotos.egg-info/top_level.txt 
    writing dependency_links to myprotos.egg-info/dependency_links.txt 
    writing manifest file 'myprotos.egg-info/SOURCES.txt' 
    reading manifest file 'myprotos.egg-info/SOURCES.txt' 
    writing manifest file 'myprotos.egg-info/SOURCES.txt' 
    Copying myprotos.egg-info to /usr/local/lib/python2.7/site-packages/myprotos-0.0.1-py2.7.egg-info 
    running install_scripts 
    writing list of installed files to '/var/folders/3t/4qwkfyr903d0b7db7by2kj6r0000gn/T/pip-M03grb-record/install-record.txt' 
    Running setup.py install for myprotos: finished with status 'done' 
    Removing source in /private/var/folders/3t/4qwkfyr903d0b7db7by2kj6r0000gn/T/pip-cFzP3I-build 
Successfully installed myprotos-0.0.1 
Cleaning up... 

這樣一切似乎都安裝成功。即使是運行pip list輸出:

$ pip list 
. 
. 
. 
myprotos (0.0.1) 
. 
. 
. 

不過,如果我嘗試導入包拋出一個ImportError。

$ python 
Python 2.7.13 (default, Jul 18 2017, 09:17:00) 
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import myprotos 
Traceback (most recent call last): 

    File "<stdin>", line 1, in <module> 
ImportError: No module named myprotos 

這裏可能會發生什麼?是不是可能是由構建腳本上安裝失敗或者是我的包定義錯了還是什麼會是什麼?

+0

我已經添加了答案。 「蛋」只是Python代碼的分佈格式。 –

回答

3

蛋的名稱不一定是相同模塊的名稱或將其打包提供。事實上,這些名稱是不同的。一個蛋可以包含多個包,所以一般不可能使用相同的名稱。此外,雞蛋名稱可以包含破折號和未在Python模塊名稱允許的其他字符。

您的Python site-packages目錄中的myprotos.egg-info目錄應包含一個名爲top_level.txt的文件,該文件列出所有頂級模塊並打包egg導出。

+0

好吧,所以我的主要問題是,所有的python都是存儲庫中的頂層,而不是嵌套在模塊中,所以沒有任何東西被添加到'top_level.txt'文件中。 – Josh