Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: matplotlib is required for plotting when the default backend "matplotlib" is selected #5994

Closed
dickreuter opened this issue Jul 10, 2021 · 3 comments · Fixed by #6180
Labels
state:need info Need more information for solve or help. triage Please triage and relabel this issue

Comments

@dickreuter
Copy link
Contributor

I recently started to get this error with the latest pyinstaller from github (and also prod versions installed via pip):

It only happens when I run the pyinstalled packaged version of my code. Any suggestions how this could be resolved? thanks


ImportError: matplotlib is required for plotting when the default backend "matplotlib" is selected.
Traceback (most recent call last):
  File "poker\gui\action_and_signals.py", line 275, in <lambda>
  File "poker\gui\action_and_signals.py", line 432, in update_strategy_analyser
  File "poker\gui\action_and_signals.py", line 446, in strategy_analyser_update_plots
  File "poker\gui\plots\bar_plotter_2.py", line 78, in drawfigure
  File "pandas\plotting\_core.py", line 892, in __call__
  File "pandas\plotting\_core.py", line 1814, in _get_plot_backend
  File "pandas\plotting\_core.py", line 1757, in _load_backend
ImportError: matplotlib is required for plotting when the default backend "matplotlib" is selected.
@dickreuter dickreuter added the triage Please triage and relabel this issue label Jul 10, 2021
@rokm
Copy link
Member

rokm commented Jul 11, 2021

This seems to be just what the error is saying - matplotlib is not present in the frozen application (which uses default pandas.plotting backend).

Can you check if build\<name>\Analysis-00.toc lists any matplotlib modules?
If not, check if the build log contains any matplotlib related messages (e.g., Loading module hook 'hook-matplotlib.py' from ...).
If not, check if the environment from which you are running pyinstaller (which may or may not be the same as the one you use when you run source version of your code) has matplotlib installed?

@rokm rokm added the state:need info Need more information for solve or help. label Jul 11, 2021
@dickreuter
Copy link
Contributor Author

dickreuter commented Jul 11, 2021 via email

@michaeleveringham
Copy link

For others having the same issue and don't want to downgrade anything, you can add import pandas.plotting._matplotlib to resolve this.


If you're trying to use plt.show() you may get UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. Explicitly setting the matplotlib backend resolves this, however, you'll have to first explicitly import the backend from matplotlib.backends and then use it.

import matplotlib
import matplotlib.backends.backend_tkagg
matplotlib.use('tkagg')

rokm added a commit to rokm/pyinstaller that referenced this issue Aug 31, 2021
Reproduces the error from pyinstaller#5994, which is caused by pandas using
importlib.import_module() to load their pandas.plotting._matplotlib
module (starting with pandas 1.3.0).
rokm added a commit that referenced this issue Sep 1, 2021
* tests: add a basic test for pandas.plotting

Reproduces the error from #5994, which is caused by pandas using
importlib.import_module() to load their pandas.plotting._matplotlib
module (starting with pandas 1.3.0).

* hooks: add hook for pandas.plotting

Ensure that pandas.plotting._matplotlib is collected on pandas
1.3.0 and later (when matplotlib is also available).
rokm added a commit that referenced this issue Sep 1, 2021
* tests: add a basic test for pandas.plotting

Reproduces the error from #5994, which is caused by pandas using
importlib.import_module() to load their pandas.plotting._matplotlib
module (starting with pandas 1.3.0).

* hooks: add hook for pandas.plotting

Ensure that pandas.plotting._matplotlib is collected on pandas
1.3.0 and later (when matplotlib is also available).
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
state:need info Need more information for solve or help. triage Please triage and relabel this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants