setuptools 和 pip:选择最小安装和完整安装 [英] setuptools and pip: choice of minimal and complete install
问题描述
我们创建了一个依赖于其他库的库.但是有必要的(例如对于服务器批处理)和可选的依赖项(例如对于具有 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
)
推荐答案
您可以在 extras_require
中安装包,方法是在方括号中附加推荐依赖项的名称(即 [mpl]
或 [bn]
在你的情况下)到 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屋!