![](/img/trans.png)
[英]pip install error: ModuleNotFoundError No module named 'setuptools'
[英]setuptools and pip: choice of minimal and complete install
我们创建了一个依赖于其他库的库。 但是有必要的(例如对于服务器批处理)和可选的依赖项(例如对于具有 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
看起来像这样:
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]
在您的情况下)来安装extras_require
中的包。
因此,要安装具有附加要求的“mylib”,您可以像这样调用 pip:
pip install 'mylib[mpl]'
pip install 'mylib[bn]'
这将首先下载并安装额外的依赖项,然后是mylib
的核心依赖项。
这与您如何使用 setuptools 声明这些依赖项类似: http ://pythonhosted.org/setuptools/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies(请参阅第三个示例中的install_requires
值)
所以 pip 实际上对安装有额外要求的库非常挑剔
pip install -e ".[extra,requirements]" # works with file paths
pip install "package[extra,requirements]" # works when downloading packages
pip install ".[extra,requirments]" # DOES NOT WORK
我认为这取决于 RequirementsSpec 解析器的工作方式,而 pip 使用-e
标志做了一些额外的魔法。 无论如何,经过多次头部撞击,这里有一个稍微丑陋的解决方法
pip install "file:///path/to/your/python_code#egg=SomeName[extra,requirements]"
egg=SomeName
部分基本上被忽略了,但是 pip 正确地获取了额外的要求
file:///
语法在 pip 中没有记录,所以我不确定它将来是否会改变。 它看起来有点像VCS 支持语法,但我有点惊讶它的工作原理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.