在setup.py或pip需求文件中,如何控制安装包依赖项的顺序?
我有一个 Python 包,其 setup.py 具有通过通常方式声明的依赖项,在 install_requires=[...] 中。其中一个软件包 scikits.timeseries 具有一个 setup.py ,期望已安装 numpy,因此,我想要某种方法来首先安装 numpy。对于这种情况以及一般情况,可以控制依赖项安装的顺序吗?如何?
目前,setup.py 获取依赖项的顺序(如 arg install_requires 中列出的)似乎几乎是随机的。另外,在 setup.py setup(...) 中,我尝试使用 arg:
extras_require={'scikits.timeseries': ['numpy']}
...没有成功,安装依赖项的顺序不受影响。
我还尝试设置 pip 需求文件,但 pip 安装依赖项的顺序与需求文件的行顺序不匹配,所以运气不好。
另一种可能性是在 setup.py 顶部附近进行系统调用,在 setup(...) 调用之前安装 numpy,但我希望有更好的方法。预先感谢您的任何帮助。
I've got a Python package with its setup.py having dependencies declared via the usual way, in install_requires=[...]. One of the packages there, scikits.timeseries, has a setup.py expecting numpy to already be installed, thus, I'd like some way to have numpy installed first. For this case and in general, can the order of dependency installation be controlled? How?
Currently the order in which setup.py pulls down dependencies (as listed in the arg install_requires) seems practically random. Also, in the setup.py setup(...) I tried using the arg:
extras_require={'scikits.timeseries': ['numpy']}
...without success, the order of installing dependencies was unaffected.
I also tried setting up a pip requirements file, but there too, pip's order of installing dependencies didn't match the line-order of the requirements file, so no luck.
Another possibility would be to have a system call near the top of setup.py, to install numpy before the setup(...) call, but I hope there's a better way. Thanks in advance for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果 scikits.timeseries 需要 numpy,那么它应该将其声明为依赖项。如果确实如此,那么
pip
将为您处理事情(我很确定setuptools
也会,但我已经很长一段时间没有使用它了)。如果您控制scikits.timeseries
,那么您应该修复它的依赖声明。If
scikits.timeseries
needsnumpy
, then it should declare it as a dependency. If it did, thenpip
would handle things for you (I'm pretty suresetuptools
would, too, but I haven't used it in a long while). If you controlscikits.timeseries
, then you should fix it's dependency declarations.使用setup_requires参数,例如安装numpy之前将scipy放入setup_requires中并添加__builtins__.__NUMPY_SETUP__ = False正确安装 numpy 的钩子:
Use
setup_requires
parameter, for instance to installnumpy
priorscipy
put it into setup_requires and add__builtins__.__NUMPY_SETUP__ = False
hook to get numpy installed correctly:这是一个实际有效的解决方案。这不是一个必须诉诸的过于“愉快”的方法,而是“绝望的时候......”。
基本上,您必须:
这样做的缺点是:
代码:
Here's a solution which actually works. It's not an overly "pleasant" method to have to resort to, but "desperate times...".
Basically, you have to:
The drawbacks to this are:
setup.py
in an environment without that.The code:
您可以将 numpy 添加到 setup_requires 部分:
You can add numpy to setup_requires section: