-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Topological sorting of subrequirements #2478
Comments
Possible duplicate of #988 |
I think this might be an interesting subset of the more general problem. If I'm not misreading #988, the biggest portion of the work required there is the SAT solver for finding the specific versions of packages that satisfy the requirements given. However, in this case, when using I believe this can be tackled separately from the broader issues of dependency version resolution mentioned in #988, and it would solve a number of issues right now where |
You are right. |
What's the order that works? Generally you should not depend on the order of |
To clarify, in my example, both The current logic does the correct thing if I do e.g. What I want is that subrequirements under |
In particular, in the documentation for setuptools, the order of installation is unspecified. It says:
It doesn't state whether things will be installed before, after, or concurrently. If you depend on something while the |
The current pip code already makes an attempt to install subrequirements before parent requirements, though. It shouldn't be more than a few dozen lines of code in It's not the case that I need The concrete issue is that, as it stands, in cases where packages require other packages for installation, the output of I think it would be a general improvement for |
Specifically, this is breaking common use case 1 of requirements files here: https://pip.pypa.io/en/latest/user_guide.html#requirements-files
|
I admit I'm a bit confused by the
For The thing that's really not ideal about putting |
The unfortunate thing is that setuptools doesn't really have "build requirements", the closest thing to them is "setup requirements". There are some hacks that you can do to solve some of the problems (like it being required for The change in ordering was to attempt to install dependencies first, primarily as a hackish way of preventing a problem like That being said, I didn't close this issue, because the solution you want would make it better for the case that the current order is attempting to solve, I'm mostly just trying to be clear here that you shouldn't rely on the order of |
That makes sense. Thank you for clarifying the issues with I'll get a PR together when I get a chance. I look forward to the more strategic solutions being deployed in the future. |
Is there any workaround for this? I have a package which requires, for instance, h5py and numpy. But "pip install mypackage" fails on h5py installation because "no module named numpy". I don't understand why numpy isn't installed before h5py. Any ideas what I can do to my setup.py to get this working? |
This is needed for setup-requires, since without it its possible to cause installation to fail in sort-circuit scenarios such as the added functional test case demonstrates.
Hi jluttine, you should make sure h5py install_requires numpy and that your setup.py can run without numpy installed. If your setup.py cannot run without numpy installed, then you should setup_requires on numpy (and you may need some lazy-import glue to permit that to work at all) - see the discussion on #2603 for more info on that. |
This is needed for setup-requires, since without it its possible to cause installation to fail in sort-circuit scenarios such as the added functional test case demonstrates.
This is needed for setup-requires, since without it its possible to cause installation to fail in sort-circuit scenarios such as the added functional test case demonstrates.
rbtcollins, thanks for the comment. Yes, h5py install_requires numpy and my setup.py can run without numpy installed. Having numpy in setup_requires for my package didn't help the installation of h5py, because h5py didn't have numpy in setup_requires. Thus, installing my package fails when installing h5py requirement (if numpy isn't installed manually beforehand). I didn't check if this has now changed. Anyway, my understanding is that there's not much I can do: either h5py should fix its setup.py or pip should behave differently. But of course, any workaround for my package would be great. And I'll take a closer look on this again. |
This is needed for setup-requires, since without it its possible to cause installation to fail in sort-circuit scenarios such as the added functional test case demonstrates.
You might as a workaround be able to specify numpy on the command line before your package, but fundamentally the bug here is in h5py: if it requires numpy to run setup.py, it needs to setup_requires it. |
This is needed for setup-requires, since without it its possible to cause installation to fail in sort-circuit scenarios such as the added functional test case demonstrates.
This is needed for setup-requires, since without it its possible to cause installation to fail in sort-circuit scenarios such as the added functional test case demonstrates.
This is needed for setup-requires, since without it its possible to cause installation to fail in sort-circuit scenarios such as the added functional test case demonstrates.
This is needed for setup-requires, since without it its possible to cause installation to fail in sort-circuit scenarios such as the added functional test case demonstrates.
This is needed for setup-requires, since without it its possible to cause installation to fail in sort-circuit scenarios such as the added functional test case demonstrates.
This is needed for setup-requires, since without it its possible to cause installation to fail in sort-circuit scenarios such as the added functional test case demonstrates.
This is needed for setup-requires, since without it its possible to cause installation to fail in sort-circuit scenarios such as the added functional test case demonstrates.
This is needed for setup-requires, since without it its possible to cause installation to fail in sort-circuit scenarios such as the added functional test case demonstrates.
Issue #2478: Topological installation order
This should be fixed now. |
@dstufft @rbtcollins Thanks for fixing this! Sorry I never got around to sending in a PR myself. |
As evidenced by #2260 and #2473, the behavior where pip installs packages as a function of the order specified, even when some packages depend on other packages, is very fragile, and occasionally leads to the output of a
pip freeze
not being valid as input to apip install -r
.The most straightforward example I can think of is
h5py
. If I installh5py
in a clean environment, my frozen requirements look like:However, if I try to
pip install -r
from these requirements, the current sorting behavior makes these packages install in the ordernumpy
h5py
Cython
However,
h5py
cannot be installed withoutCython
already being installed first (andCython
is specified ininstall_requires
).I believe the correct way to handle this is for pip to do a topological sort of the requirements, and ensure that subrequirements are installed before their parent requirements, regardless of the order in which requirements are specified.
The text was updated successfully, but these errors were encountered: