question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Matplotlib pulls numpy: make lib optional

See original GitHub issue

I 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:open
  • Created 3 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
danieleadescommented, May 5, 2022

this is causing me a headache right now, as i’m having build issues when installing numpy

1reaction
danwoscommented, Mar 17, 2021

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found