setuptools和pip:选择最小和完整安装 [英] setuptools and pip: choice of minimal and complete install

查看:79
本文介绍了setuptools和pip:选择最小和完整安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经建立了一个依赖于其他库的库.但是有必要(例如,用于服务器批处理)和可选的依赖项(例如,具有GUI的客户端).

We've made a library which depends on other libraries. But there are necessary (e.g. for server batch processing) and optional dependencies (e.g. for clients with GUI).

是否可能这样:

pip install mylib.tar.gz  # automatically downloads and installs with the minimal set of dependencies

pip install mylib.tar.gz  --install-option="complete"  # automatically installs with all dependencies

我已经找到了extra_require标志,但是如何告诉pip使用它们? setup.py看起来像这样:

I've found the extra_require flag, but how can I tell pip to use them? The setup.py looks like this:

from setuptools import setup

# ...

# Hard library depencencies:
requires = [
    "numpy>=1.4.1",
    "scipy>=0.7.2",
    "traits>=3.4.0"
]

# Soft library dependencies:
recommended = {
    "mpl": ["matplotlib>=0.99.3"],
    "bn": ["bottleneck>=0.6"]
}

# ...

# Installer parameters:
setup(
    name = "mylib",
    #...
    install_requires = requires,
    extras_require = recommended
)

推荐答案

您可以通过在方括号中添加建议的依赖项的名称(例如您的情况下为[mpl][bn])来将软件包安装在extras_require中.到pip中的包裹名称.

You can install the packages in extras_require by appending the name of the recommended dependency in square brackets (i.e. [mpl] or [bn] in your case) to the package name in pip.

因此,要安装具有附加要求的"mylib",您将像这样调用pip:

So to install 'mylib' with the additional requirements, you would call pip like this:

pip install 'mylib[mpl]'
pip install 'mylib[bn]'

这将首先下载并安装额外的依赖项,然后是mylib的核心依赖项.

This will first download and install the extra dependencies, and then mylib's core dependencies.

这与您使用setuptools声明那些依赖关系十分相似: http://pythonhosted.org/setuptools/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies (请参见第三个示例中的install_requires值)

This is anologous to how you declare those dependencies with setuptools: http://pythonhosted.org/setuptools/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies (see the install_requires value in the third example)

这篇关于setuptools和pip:选择最小和完整安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆