Matplotlib pulls numpy: make lib optional
See original GitHub issueI was surprised to find numpy
as part of my dependencies when I don’t do any maths.
NumPy is a fantastic tool, but it’s heavy and clearly unnecessary for my project. It turns out, numpy is a required dependency of matplotlib
, which is now part of needs
deps since 0.5.0.
I won’t personally be doing any pie-chart-ing, so wouldn’t really benefit from use of matplotlib, nor numpy. Can we make the matplotlib
an optional dependency please? This way, people who are in more “constrained” systems don’t need to pull in the whole maths ecosystem.
From setuptools docs on Optional Dependencies, adapted for us:
extras_require={
"matplotlib": ["matplotlib"],
}
As for gating the feature in python, from SO:
try:
import matplotlib
except ImportError:
# dependency missing, issue a warning
import warnings
warnings.warn('matplotlib not found, please install 'matplotlib' extra to enable pie-charts')
I realize there’s a documentation overhead to doing this, but think it’s worth it.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
2. Manipulating and plotting data in Python: numpy, and ...
Manipulating and plotting data in Python: numpy , and matplotlib libraries¶. Table of Contents. While Python has a rich set of modules and...
Read more >Dependencies — Matplotlib 3.6.2 documentation
Optional : In addition to all of the optional dependencies on the main library, for testing the following will be used if they...
Read more >NumPy: the absolute basics for beginners
NumPy can be used to perform a wide variety of mathematical operations on arrays. It adds powerful data structures to Python that guarantee...
Read more >An introduction to Numpy and Matplotlib - Python for Engineers
We import it as np to save typing numpy each time. This is a common pattern in Python, though it is optional. You...
Read more >Python Numpy Tutorial (with Jupyter and Colab)
A Jupyter notebook lets you write and execute Python code locally in your ... We will often define functions to take optional keyword...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
this is causing me a headache right now, as i’m having build issues when installing numpy
Yes, I agree. There are some (huge) dependencies, which are used for some directives only and therefore are often not needed for most use-cases.
Instead of a warning I would like to throw an exception, as the final documentation build will not contain the expected content (e.g. no pie charts). Otherwise I’m afraid that a user may miss the warning, as sphinx-build logs are normally not so small.
This could also be configurable, e.g.
needs_missing_import_exceptions = False
(True
is default).Any concerns about raising an exception and stopping build in such a case?