Skip to content

Remove default dependencies - #4967

Merged
jarrodmillman merged 2 commits into
networkx:mainfrom
jarrodmillman:default-deps
Jul 24, 2021
Merged

jarrodmillman merged 2 commits into
networkx:mainfrom
jarrodmillman:default-deps

Conversation

@jarrodmillman

@jarrodmillman jarrodmillman commented Jul 9, 2021 •

Copy link
Copy Markdown
Member

Having scipy as a default dependency introduce a circular build dependency issue for scipy: scipy/scipy#14335 and serge-sans-paille/pythran#1837

This PR removes numpy, scipy, matplotlib, and pandas as "default" dependencies for NetworkX. With this PR,

pip install networkx

requires installing no additional packages and we will ask users to install networkx via

pip install networkx[default]

I propose releasing networkx 2.6.2 with this PR merged and removing 2.6.0 and 2.6.1. I would still like to figure out a way for users to install networkx with its "default" dependencies using only

pip install networkx

for 2.7. Currently, I think we may want to release two packages on PyPI:

  • networkx-core for libraries that only need a small subset of our functionality and that are not interested in installing extra packages
  • networkx for end-users who don't care about which libraries we use to provide basic functionality.

Of course, we will need to think through this a bit and we may need to work with projects (like pythran) that depend on us.

@stefanv

stefanv commented Jul 9, 2021

Copy link
Copy Markdown
Contributor

@jarrodmillman With the lazy loader approach, we can also improve the error messages on SciPy import failure to guide users. So, I think this is a reasonable workaround for now.

We still have an open issue on pypa to deal with networkx[min] (i.e. reduce the dependency set), but until that feature is added this will have to do.

@jarrodmillman

jarrodmillman commented Jul 9, 2021 •

Copy link
Copy Markdown
Member Author

It would also be nice if --no-deps was understood by setup.py for things like install_requires.

@h-vetinari

Copy link
Copy Markdown

Thanks for responding so quickly on this, much appreciated. I think networkx-core would also be a fine solution (modulo a bit of migration pain, but possibly/likely everyone happier in the longterm).

@jarrodmillman

Copy link
Copy Markdown
Member Author

pythran is fixing the problem on their end: serge-sans-paille/pythran#1839

So this is less pressing for us now. I will likely wait to see if we run into additional circular imports for other projects.

@freddyaboulton

Copy link
Copy Markdown

I think it's still worth making this change. I have a package where matplotlib is listed as an optional dependency and networkx is listed as a core dependency. Version 2.6 breaks that for us and there's no way to specify --no-deps for a single dependency in a requirements.txt file as far as I know.

Making it so that I can avoid matplotlib via

pip install networkx[default]

or

pip install networkx-core

would give us control over when our plotting dependencies are installed.

@rossbar rossbar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted by @stefanv , this change will break the functions for which we switched to the scipy-based implementations like pagerank. If a user calls nx.pagerank with this patch they will get ModuleNotFoundError: No module named 'scipy'.

There are several options for the instances like this:

  1. Revert these changes so that the non-numpy/scipy implementations are used (i.e. the same inefficient implementations that were used in 2.5)
  2. Add some try/except boilerplate to fall back to the pure-Python implementations when the necessary dependencies aren't found.
  3. Leave things as-is: This will break functions like pagerank for users of v2.6 who don't have numpy/scipy installed.
  4. Leave things as is, but add boilerplate to improve exception messages - i.e. same as 3 but with a message like "scipy is required for pagerank" instead of the more terse "No module named scipy".

I prefer option 2 for the short-term fix, just to avoid breaking pagerank et. al. for the subset of users who don't have numpy/scipy installed when they upgrade from 2.5->2.6

@jarrodmillman

Copy link
Copy Markdown
Member Author

Having to revert back to the pure-Python versions is annoying. They were often so slow that it was painful to run. I hope they aren't being used by folks, but maybe they are. That said, I agree that we should go with option 2 if we are going to merge this PR.

@rossbar Should we remove 2.6.0 and 2.6.1 from PyPI now? I would like to take some more time to think through the implications of removing the numpy, scipy, pandas, and matplotlib dependencies. I think we just need to fix pagerank, simrank_similarity, and hits. But I need to start focusing on my SciPy talk and I don't want to have to release a 2.6.3 b/c we missed something.

@rossbar

rossbar commented Jul 9, 2021

Copy link
Copy Markdown
Contributor

I would like to take some more time to think through the implications of removing the numpy, scipy, pandas, and matplotlib dependencies.

I agree that having some time to thinking about this more would be good.

Should we remove 2.6.0 and 2.6.1 from PyPI now?

This seems reasonable to me if it's sufficient to fix the immediate problems that scipy et. al. are experiencing.

@jarrodmillman

Copy link
Copy Markdown
Member Author

I just "yanked" 2.6 and 2.6.1 from PyPI:

I can "un-yank" them if we want.

@rossbar

rossbar commented Jul 9, 2021

Copy link
Copy Markdown
Contributor

Also the test suite should be failing here for e.g. pagerank - it's currently not because we forgot to remove the pytest.importorskips from the top of the files when we made the scipy implementation the default.

I'll go back over the PRs we had for 2.6 where we switched to a numpy or scipy version of an algorithm and double check these instances so that the tests are failing properly and we can address them via e.g. option 2. I won't be able to take a look at this immediately however, so +1 for yanking 2.6 until we have a bit more bandwidth.

@jarrodmillman

jarrodmillman commented Jul 9, 2021 •

Copy link
Copy Markdown
Member Author

I think we don't want the test suite to fail. We left pytest.importorskip in place because we still want people to be able to run with --no-deps without errors. For example, we want the tests to pass on PyPy. If we are changing these functions so that they run with whatever you happen to have installed, then I am not sure we want to use pytest.importorskip. I need to think about it a bit and maybe look at a PR.

@dschult

dschult commented Jul 10, 2021

Copy link
Copy Markdown
Member

I am +1 on removing all dependencies for NetworkX 2.6. The default and extras options should be used when possible. But it sounds like pypi doesn't have a good way to set that up.

I don't know much about the magic that these words mean, but it seems like we need a networkx[minimal] a networkx[default] (or maybe recommended?) and a networkx[extras]. And we need pypi to allow options like this is standard requirements.txt files (and maybe conda use of requirements files too). It seems like a wart that pypi "requirements" files use only one set of dependencies -- or maybe I'm just missing how e.g. Pythran could require a minimal set of requirements.

Also, we should write down somewhere what the advantages of including these requirements are. We've talked about it before, but it seems that they aren't at the tip of our tongues in important moments like this. Perhaps part of getting v2.7 released with these dependencies is to write an NXEP (or maybe a SPEC or maybe both) about how to handle dependencies. Strong buy-in for something like that could influence pypi, if needed.

Thanks for everyone thinking about this -- it is helpful! And Thanks to Jarrod and Ross for working through so many details.

@rgommers

Copy link
Copy Markdown

it seems like we need a networkx[minimal] a networkx[default] (or maybe recommended?) and a networkx[extras]
...
And we need pypi to allow options like this is standard requirements.txt files (and maybe conda use of requirements files too)

Some context that may be helpful here:

  • requirements.txt is not a thing PyPI knows about, it's an ad-hoc lock-file-type-thing that gets turned into something setuptools-specific. It works with pip install networkx only because in your setup.py file you have:
install_requires = parse_requirements_file("requirements/default.txt")
extras_require = {
    dep: parse_requirements_file("requirements/" + dep + ".txt")
    for dep in ["developer", "doc", "extra", "test"]
}

@h-vetinari

Copy link
Copy Markdown

conda does not have this feature. It will let a package author give constraints for optional dependencies with run_constrained in metadata.yaml, but there's no way to tell conda "install all optional dependencies".

Just to elaborate on that a bit, while conda does not have a concept of optional dependencies, it trivially supports multiple outputs per recipe. I haven't seen this fully formalized, but packages with many extras often get a mapping à la pip install package[extra] -> conda install package-extra (including package-all if desired). There are several examples, here's one.

@dschult dschult left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks Good To Me. :}

@rossbar rossbar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as well, thanks @jarrodmillman !

@jarrodmillman
jarrodmillman merged commit 5b86d91 into networkx:main Jul 24, 2021
@jarrodmillman
jarrodmillman deleted the default-deps branch July 24, 2021 00:29
skshetry referenced this pull request in treeverse/dvc Aug 16, 2021
Networkx v2.6.2 now does not require any additional requirements. All of the other 2.6 releases have been yanked. So, it's safe for us to unpin it.
dschult pushed a commit to dschult/networkx that referenced this pull request Jan 25, 2022
* Remove default dependencies

* Update release notes
MridulS pushed a commit to MridulS/networkx that referenced this pull request Feb 4, 2023
* Remove default dependencies

* Update release notes
cvanelteren pushed a commit to cvanelteren/networkx that referenced this pull request Apr 22, 2024
* Remove default dependencies

* Update release notes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

7 participants