2013-06-27 59 views
2

UPDATE兩個包:當使用setup.py安裝包都獨自在安裝就好了。當提取由sdist生成的tarball並安裝它們時,會發生相同的錯誤。這意味着問題在我猜測setuptools內的某個地方。無法安裝使用相同的命名空間

我開發的有兩個包命名的兩個項目:測試套件和testsuite.prettyprint。 這兩個命名空間包__init__.py包含:

__import__('pkg_resources').declare_namespace(__name__) 

下面是testsuite.prettyprint.outcomes的setup.py:

import pkgutil 
from setuptools import setup 


def get_packages(): 
    return [name for _, name, is_package in pkgutil.walk_packages('.') if name.startswith('testsuite') and is_package] 

dependencies = ['nose2>=0.4.6', 'colorama>=0.2.5'] 

setup(
    name='testsuite-prettyprint-outcomes', 
    version='0.1.0-alpha.1', 
    packages=get_packages(), 
    url='', 
    license='BSD3', 
    author='Omer Katz', 
    author_email='[email protected]', 
    description='testsuite-prettyprint-outcomes is a nose2 plugin that prettyprints test outcomes.', 
    namespace_packages=['testsuite', 'testsuite.prettyprint'], 
    install_requires=dependencies 
) 

這裏是testsuite.prettyprint.traceback的setup.py:

import pkgutil 
import sys 

from setuptools import setup 


def get_packages(): 
    return [name for _, name, is_package in pkgutil.walk_packages('.') if name.startswith('testsuite') and is_package] 

dependencies = ['nose2>=0.4.6', 'pygments>=1.6'] 

if sys.platform == 'win32': 
    dependencies.append('colorama>=0.2.5') 

setup(
    name='testsuite-prettyprint-traceback', 
    version='0.1.0-alpha.2', 
    packages=get_packages(), 
    url='', 
    license='BSD3', 
    author='Omer Katz', 
    author_email='[email protected]', 
    description='testsuite-prettyprint-traceback is a nose2 plugin that prettyprints traceback on failures and errors.', 
    namespace_packages=['testsuite', 'testsuite.prettyprint'], 
    install_requires=dependencies 
) 

安裝時他們倆拒不安裝一個:

pip install testsuite-prettyprint-outcomes testsuite-prettyprint-traceback --use-mirrors 
Downloading/unpacking testsuite-prettyprint-outcomes 
    Downloading testsuite-prettyprint-outcomes-0.1.0-alpha.1.tar.gz 
    Running setup.py egg_info for package testsuite-prettyprint-outcomes 

Downloading/unpacking testsuite-prettyprint-traceback 
    Downloading testsuite-prettyprint-traceback-0.1.0-alpha.2.tar.gz 
    Running setup.py egg_info for package testsuite-prettyprint-traceback 

Downloading/unpacking nose2>=0.4.6 (from testsuite-prettyprint-outcomes) 
    Running setup.py egg_info for package nose2 

    warning: no previously-included files matching '__pycache__' found anywhere in distribution 
    warning: no previously-included files matching '*~' found anywhere in distribution 
    warning: no previously-included files matching '*.pyc' found anywhere in distribution 
Downloading/unpacking colorama>=0.2.5 (from testsuite-prettyprint-outcomes) 
    Downloading colorama-0.2.5.zip 
    Running setup.py egg_info for package colorama 

Downloading/unpacking pygments>=1.6 (from testsuite-prettyprint-traceback) 
    Downloading Pygments-1.6.tar.gz (1.4MB): 1.4MB downloaded 
    Running setup.py egg_info for package pygments 

Downloading/unpacking six>=1.1,<1.2 (from nose2>=0.4.6->testsuite-prettyprint-outcomes) 
    Running setup.py egg_info for package six 

Installing collected packages: testsuite-prettyprint-outcomes, testsuite-prettyprint-traceback, nose2, colorama, pygments, six 
    Running setup.py install for testsuite-prettyprint-outcomes 
    Skipping installation of /home/omer/.virtualenvs/test/lib/python3.2/site-packages/testsuite/__init__.py (namespace package) 
    Skipping installation of /home/omer/.virtualenvs/test/lib/python3.2/site-packages/testsuite/prettyprint/__init__.py (namespace package) 

    Installing /home/omer/.virtualenvs/test/lib/python3.2/site-packages/testsuite_prettyprint_outcomes-0.1.0_alpha.1-py3.2-nspkg.pth 
    Running setup.py install for testsuite-prettyprint-traceback 
    error: package directory 'testsuite/prettyprint/outcomes' does not exist 
    Complete output from command /home/omer/.virtualenvs/test/bin/python3.2 -c "import setuptools;__file__='/home/omer/.virtualenvs/test/build/testsuite-prettyprint-traceback/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-12l9lq-record/install-record.txt --single-version-externally-managed --install-headers /home/omer/.virtualenvs/test/include/site/python3.2: 
    running install 

running build 

running build_py 

creating build 

creating build/lib 

creating build/lib/testsuite 

copying testsuite/__init__.py -> build/lib/testsuite 

creating build/lib/testsuite/prettyprint 

copying testsuite/prettyprint/__init__.py -> build/lib/testsuite/prettyprint 

error: package directory 'testsuite/prettyprint/outcomes' does not exist 

---------------------------------------- 
Command /home/omer/.virtualenvs/test/bin/python3.2 -c "import setuptools;__file__='/home/omer/.virtualenvs/test/build/testsuite-prettyprint-traceback/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-12l9lq-record/install-record.txt --single-version-externally-managed --install-headers /home/omer/.virtualenvs/test/include/site/python3.2 failed with error code 1 in /home/omer/.virtualenvs/test/build/testsuite-prettyprint-traceback 
Storing complete log in /home/omer/.pip/pip.log 

我無法弄清楚什麼是錯的。即使你改變安裝順序,它說它找不到其他的。

+0

@abarnert單獨安裝它們中的任何一個。安裝兩者都不**。 –

+0

你爲'setup.py'文件的'namespace_packages'條目輸入了什麼內容? –

+0

@MartijnPieters都包含['testsuite','testsuite.prettyprint']。我檢查,當我sdist namespace_packages.txt包含兩個。 –

回答

3

在安裝軟件,而且下載後,其他...

你不包括在源文件中testsuite/__init__.pytestsuite/prettyprint/__init__.py

Namespace Packages該文檔的setuptools/pkg_resources方式解釋說:

注意,順便說一下,您的項目的源代碼樹必須包括命名空間包__init__.py文件(及任何父包的__init__.py)在一個普通的Python包佈局中。

如果你實際上沒有安裝這些文件,它們沒有任何好處。你剛剛結束了與什麼也沒有,但prettyprint一個testsuite,並沒有任何關係,但outcomes,所以testsuitetestsuite.prettyprint不是包可言,更不用說命名空間的包。

+0

我如何將它們包括在內? –

+1

等一下,讓我弄清楚爲什麼他們不被列入,我會編輯答案。 – abarnert

+0

我剛剛檢查並get_packaged正確返回所有包。 –

-2

我看你使用的是virtualenv。通常,當我遇到你正面臨的錯誤時,是因爲這些軟件包與virtualenv不兼容。

您是否嘗試過在主python安裝文件夾中安裝軟件包? (不在的virtualenv)

我想,這是因爲一些setup.py文件作出關於主機環境的假設和不遵循setup.py最佳實踐。

如果你仍然堅持試試看。

0

name是你的包看上去是錯誤的。我只是將一個項目分成了子包,而我做的另一件事是讓每個name匹配namespace_packages的組件。

因此,對於testsuite.prettyprint.outcomes

setup(
     name='testsuite.prettyprint.outcomes', 
     [...] , 
     namespace_packages=['testsuite', 'testsuite.prettyprint'] 
) 

而對於testsuite.prettyprint.traceback

setup(
     name='testsuite.prettyprint.traceback', 
     [...] , 
     namespace_packages=['testsuite', 'testsuite.prettyprint'] 
) 

爲了這個正常工作,你需要提供__init__.py腳本,就像你已經所示,所有父級namespace_package級別(即低至testsuite.prettyprint)。

生產包中的namespace_packages的好例子可以在zope子包中找到。

例如請參閱zope.app.cachesetup.py腳本,在http://svn.zope.org/zope.app.cache/trunk/setup.py?view=markup

+0

但是,它們將不能作爲testsuite-prettyprint-traceback進行安裝。我指定包名稱是有原因的。這是我們試圖在setuptools中追蹤的錯誤嗎? –

相關問題