cantools icon indicating copy to clipboard operation
cantools copied to clipboard

Forced installation of matplotlib

Open AxelVoitier opened this issue 4 years ago • 6 comments

Hello,

I noticed the new plot feature is creating a hard dependency on matplotlib. Can this be avoided?

We are installing this package on restricted embedded targets. Just declaring the dependency creates all kind of issues just by installing cantools: from disk usage to compilation time (as it goes through qemu ARM emulation). Especially since matplotlib also depends on numpy...

Can that be declared as an extras in setup.py? And have the main be clever enough to skip on adding subparsers when their importation fails?

Also related is that comment in the main about curses (which actually used to create us issues in the past, as we did not have it on the target :D).

I can send a PR for that later (some times in February, maybe).

Cheers, Axel

AxelVoitier avatar Jan 28 '21 18:01 AxelVoitier

I understand. Feel free to submit a PR that makes all troublesome dependencies optional. One option could be to split the cantools package into one core package and one or more smaller for certain tools. But let's try to avoid that.

eerimoq avatar Jan 28 '21 19:01 eerimoq

This also affects us: we're running cantools on a resource- and bandwidth-constrained platform and would rather remove the install hacks that uninstall matplotlib after installing cantools :)

tjhowse avatar Jan 28 '21 23:01 tjhowse

I am running cantools 36.2.0 on "raspbian-server" without graphical (X) environment, and installed matplotlib 3.3.4

$ pip show matplotlib
Name: matplotlib
Version: 3.3.4
Summary: Python plotting package
Home-page: https://matplotlib.org
Author: John D. Hunter, Michael Droettboom
Author-email: [email protected]
License: PSF
Location: /home/pi/.local/lib/python3.7/site-packages
Requires: python-dateutil, pyparsing, pillow, kiwisolver, cycler, numpy
Required-by:

commands like cantools decode shows this error

matplotlib package not installed. Required for producing plots.
Traceback (most recent call last):
  File "/home/pi/.local/bin/cantools", line 10, in <module>
    sys.exit(_main())
  File "/home/pi/.local/lib/python3.7/site-packages/cantools/__init__.py", line 38, in _main
    from .subparsers import plot
  File "/home/pi/.local/lib/python3.7/site-packages/cantools/subparsers/plot.py", line 59, in <module>
    plt.rcParams["date.autoformatter.hour"] = "%H:%M"
NameError: name 'plt' is not defined

trying to use matplotlib alone just to test its installation it doesn't work.

As a workaround I reverted to cantools 35.5.0 but if there's a way to use the latest version without the need for a working matplotlib, it would be better.

segaura avatar Feb 16 '21 18:02 segaura

I will give it a go, I have more time to work on it right now.

AxelVoitier avatar Feb 17 '21 08:02 AxelVoitier

Actually, #265 should fixes your issue @segaura. It's a matter of having it in a released version now.

I will just add an extra in setup.py for plot that will declare a dependency on matplotlib, and document it in README.rst.

AxelVoitier avatar Feb 17 '21 09:02 AxelVoitier

@AxelVoitier Feel free to review, merge and tag the fix. Tagged commits are automatically published on PyPI, so it should be easy. I'll be less active in the project from now on and I hope everyone interested in cantools will figure out a way for it to continue being successful.

eerimoq avatar Feb 17 '21 09:02 eerimoq