无法安装两个使用相同命名空间的包

时间:2013-06-27 09:01:58

标签: python namespaces pip setuptools

更新:仅使用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

我无法弄清楚出了什么问题。即使你改变了安装顺序,它也说不能找到另一个。

3 个答案:

答案 0 :(得分:3)

安装其中一个软件包并下载其他软件包后......

您未在源文件中加入testsuite/__init__.pytestsuite/prettyprint/__init__.py

Namespace Packages setuptools / pkg_resources方式的文档解释了:

  

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

如果您实际上没有安装这些文件,它们就没有任何好处。您最后只有一个testsuite但其中没有任何内容,只有prettyprint,除了outcomes之外没有任何内容,因此testsuitetestsuite.prettyprint不是包完全没有名称空间包。

答案 1 :(得分: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子包中找到。

e.g。请参阅http://svn.zope.org/zope.app.cache/trunk/setup.py?view=markup

上的zope.app.cache setup.py脚本

答案 2 :(得分:-2)

我看到你正在使用virtualenv。通常当我遇到你所面临的错误时,因为这些包与virtualenv不兼容。

您是否尝试在主python安装文件夹上安装软件包? (不是在virtualenv)

我认为这是因为某些setup.py文件对主机环境做出了假设,并且没有遵循setup.py最佳做法。

如果你仍然卡住试一试。