2

更新:单独使用 setup.py 安装两个软件包时,它们安装得很好。提取 sdist 生成的 tarball 并安装它们时,会发生相同的错误。这意味着我猜问题出在 setuptools 内部的某个地方。

我开发了两个具有两个命名空间包的项目:testsuite 和 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='omer.drow@gmail.com',
    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='omer.drow@gmail.com',
    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

我不知道出了什么问题。即使您更改安装顺序,它也会说找不到另一个。

4

3 回答 3

3

在安装一个包并下载另一个包之后……</p>

您没有在源文件中包含testsuite/__init__.py和。testsuite/prettyprint/__init__.py

命名空间包上的文档setuptools/pkg_resources方式解释:

请注意,顺便说一下,您的项目的源代码树必须在正常的 Python 包布局中包含命名空间包的__init__.py文件(以及任何父包的文件)。__init__.py

如果您实际上不安装这些文件,它们就没有任何好处。你最终会得到 atestsuite里面什么都没有 but prettyprint,并且里面什么都没有 but outcomes,所以testsuiteandtestsuite.prettyprint根本就不是包,更不用说命名空间包了。

于 2013-06-27T09:33:37.620 回答
0

您的包裹的names 看起来不对。我只是将一个项目分成子包,我做的一件事不同的是让每个子包都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_packagetestsuite.prettyprint

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

例如参见zope.app.cache setup.py脚本,位于http://svn.zope.org/zope.app.cache/trunk/setup.py?view=markup

于 2013-07-06T07:56:32.420 回答
-2

我看到你正在使用 virtualenv。通常,当我遇到您所面临的错误时,是因为这些软件包不能很好地与 virtualenv 一起使用。

您是否尝试在您的主要 python 安装文件夹中安装软件包?(不在虚拟环境中)

我认为发生这种情况是因为某些 setup.py 文件对主机环境做出了假设并且不遵循 setup.py 最佳实践。

如果您仍然被卡住,请尝试一下。

于 2013-07-05T18:22:23.060 回答