简体   繁体   English

无法安装使用相同名称空间的两个软件包

[英]Cannot install two packages that use the same namespace

UPDATE: When installing both packages using setup.py alone they install just fine. 更新:当单独使用setup.py安装两个软件包时,它们的安装就很好。 When extracting the tarballs generated by sdist and installing them the same error occurs. 提取sdist生成的tarball并安装它们时,会发生相同的错误。 This means that the problem is somewhere inside setuptools I guess. 这意味着问题出在我猜的setuptools内部。

I developed two projects that have two namespace packages: testsuite and testsuite.prettyprint. 我开发了两个具有两个名称空间包的项目:testsuite和testsuite.prettyprint。 Both of these namespace packages' __init__.py contain: 这两个名称空间包的__init__.py都包含:

__import__('pkg_resources').declare_namespace(__name__)

Here's the setup.py for testsuite.prettyprint.outcomes: 这是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
)

and here is the setup.py for testsuite.prettyprint.traceback: 这是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
)

When installing them both it refuses to install one: 当安装它们两者时,它拒绝安装一个:

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

I can't figure out what is wrong. 我不知道怎么了。 Even if you change the order of installation it says it can't find the other. 即使您更改安装顺序,它也会说找不到其他安装顺序。

After installing one of your packages and downloading the other… 在安装完一个软件包并下载了另一个软件包之后……

You're not including testsuite/__init__.py and testsuite/prettyprint/__init__.py in the source files. 您不在源文件中包含testsuite/__init__.pytestsuite/prettyprint/__init__.py

The docs on Namespace Packages the setuptools / pkg_resources way explains: 命名空间包上的文档setuptools / pkg_resources方式说明:

Note, by the way, that your project's source tree must include the namespace packages' __init__.py files (and the __init__.py of any parent packages), in a normal Python package layout. 请注意,顺便说一下,项目的源树必须以正常的Python包布局包含名称空间包的__init__.py文件(以及任何父包的__init__.py )。

If you don't actually install these files, they don't do any good. 如果您实际上没有安装这些文件,那么它们将无济于事。 You just end up with a testsuite with nothing in it but prettyprint , and that has nothing in it but outcomes , so testsuite and testsuite.prettyprint are not packages at all, much less namespace packages. 你刚刚结束了一个testsuite包含任何东西,但prettyprint ,并没有任何关系,但outcomes ,所以testsuitetestsuite.prettyprint不是包可言,更不用说命名空间的包。

The name s of your packages look wrong. 您的软件包name看起来不正确。 I just separated a project out into subpackages, and one thing I did differently was to make each name match the components of the namespace_packages . 我只是将一个项目分成子包,而我做的另一件事是使每个namenamespace_packages的组件匹配。

So, for testsuite.prettyprint.outcomes : 因此,对于testsuite.prettyprint.outcomes

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

And for testsuite.prettyprint.traceback : 对于testsuite.prettyprint.traceback

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

For this to work properly, you'll need to provide __init__.py scripts, like you've already shown, for all the parent namespace_package levels (ie down to testsuite.prettyprint ). 为了__init__.py正常工作,您需要为所有父namespace_package级别(例如,向下到testsuite.prettyprint )提供__init__.py脚本(如已显示)。

Good examples of namespace_packages in production packages can be found in the zope sub-packages. 可以在zope子包中找到生产包中的namespace_packages好示例。

eg See the zope.app.cache setup.py script, at http://svn.zope.org/zope.app.cache/trunk/setup.py?view=markup 例如,请参见zope.app.cache setup.py脚本, 网址http://svn.zope.org/zope.app.cache/trunk/setup.py?view=markup

I see you are using virtualenv. 我看到您正在使用virtualenv。 Usually when I encounter that error your are facing is because the packages don't work well with virtualenv. 通常,当我遇到该错误时,您面临的原因是这些软件包无法与virtualenv一起正常工作。

Have you tried installing the packages on your main python install folder? 您是否尝试过在主python安装文件夹中安装软件包? (not in virtualenv) (不在virtualenv中)

I think this happens because some setup.py files make assumptions about the host environment and don't follow the setup.py best practices. 我认为发生这种情况是因为某些setup.py文件对主机环境进行了假设,并且没有遵循setup.py最佳实践。

If you are still stuck give it a try. 如果仍然卡住,请尝试一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM