Skip to content

Conversation

mspi92
Copy link

@mspi92 mspi92 commented Aug 13, 2025

First of all: Excuse me for not opening an issue first, but the fix is so small that I thought I might as well :D

I discovered that matplotlib is listed as a hard dependency in pyproject.toml which will always be installed.
This contradicts the optional pymoo[visualization] depency and the wrapper implemented for matplotlib in pymoo.visualization.matplotlib.

I suspect that the entry was falsely copied over when migrating from the setup.py to pyproject.toml.

Thank you very much

@tpgillam
Copy link
Collaborator

Thanks for the PR! I agree that removing matplotlib as a mandatory dependency would be great.

However, some of the pymoo library would currently be unimportable without matplotlib being installed, so I think it is actually a mandatory dependency. e.g.

My usual stance is that a library should be fully importable without any extras installed. But that certain functions may fail when called (with a helpful error message) if certain extras aren't installed. Usually that means performing the import of the optional dependency within a function, rather than at the top level of a module, and handling the case that an ImportError is raised.

(It would be nice if we had a test in the suite that imported pymoo and all its submodules recursively, as that would verify that the above).

@mspi92
Copy link
Author

mspi92 commented Aug 14, 2025

Thanks for the response.
I also noticed the 2 extra imports and thought that these are optional anyways and wasn't sure how to deal with it.
I resolved these direct library imports now:

  1. For running_metric:
    As RunningMetricAnimation is inheriting AnimationCallback RunningMetricAnimation can't be defined without matplotlib installed (unless AnimationCallback class gets rewritten as well). With the case switch implemented this should be compatible now
  2. For value_functions:
    Here especially it seems to me that the plot_vf functionality is used as a debugging functionality. In this case importing matplotlib locally should do the trick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants