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

Rasa setting a platform specific matplotlib backend fails #4657

Closed
elyase opened this issue Oct 22, 2019 · 4 comments
Closed

Rasa setting a platform specific matplotlib backend fails #4657

elyase opened this issue Oct 22, 2019 · 4 comments
Labels
status:stale type:bug 🐛 Inconsistencies or issues which will cause an issue or problem for users or implementors.

Comments

@elyase
Copy link

elyase commented Oct 22, 2019

Rasa version:
1.4.0

Python version:
3.7.4

Operating system (windows, osx, ...):
Linux Ubuntu 18.04.3 LTS

Issue:
Rasa tries to set a matplotlib backend which is environment specific (and IMO also unnecessary) and fails in headless environments. According to matplotlib docs:

Likewise, the Tk framework (TkAgg backend) does not require any external dependencies and is normally always available. On certain Linux distributions, a package named python-tk (or similar) needs to be installed.

I think this line is the culprit and would be best to just delete it as it is not clear what the motivation is for that line anymore (seems to be based on an old OSX specific issue).

rasa/rasa/core/test.py

Lines 19 to 21 in 5119efc

import matplotlib
matplotlib.use("TkAgg")

In addition it would be better if matplotlib is imported inside the function call and not module wide (see here for rationale).

Error (including full traceback):

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
~/test/test-testsuite/source/initializer/tests/test_datapoint.py in 
----> 1 from rasa.core.interpreter import RegexInterpreter

~/miniconda3/envs/test/lib/python3.7/site-packages/rasa/__init__.py in 
      7 
      8 from rasa.run import run
----> 9 from rasa.train import train
     10 from rasa.test import test
     11 

~/miniconda3/envs/test/lib/python3.7/site-packages/rasa/train.py in 
      5 from typing import Text, Optional, List, Union, Dict
      6 
----> 7 from rasa.importers.importer import TrainingDataImporter
      8 from rasa import model
      9 from rasa.core.domain import Domain

~/miniconda3/envs/test/lib/python3.7/site-packages/rasa/importers/importer.py in 
      5 
      6 from rasa.core.domain import Domain
----> 7 from rasa.core.interpreter import RegexInterpreter, NaturalLanguageInterpreter
      8 from rasa.core.training.structures import StoryGraph
      9 from rasa.nlu.training_data import TrainingData

~/miniconda3/envs/test/lib/python3.7/site-packages/rasa/core/__init__.py in 
      4 
      5 from rasa.core.train import train
----> 6 from rasa.core.test import test
      7 from rasa.core.visualize import visualize
      8 

~/miniconda3/envs/test/lib/python3.7/site-packages/rasa/core/test.py in 
     19 import matplotlib
     20 
---> 21 matplotlib.use("TkAgg")
     22 
     23 logger = logging.getLogger(__name__)

~/miniconda3/envs/test/lib/python3.7/site-packages/matplotlib/cbook/deprecation.py in wrapper(*args, **kwargs)
    305                 f"for the old name will be dropped %(removal)s.")
    306             kwargs[new] = kwargs.pop(old)
--> 307         return func(*args, **kwargs)
    308 
    309     # wrapper() must keep the same documented signature as func(): if we

~/miniconda3/envs/test/lib/python3.7/site-packages/matplotlib/__init__.py in use(backend, warn, force)
   1307         if force:
   1308             from matplotlib.pyplot import switch_backend
-> 1309             switch_backend(name)
   1310     else:
   1311         # Finally if pyplot is not imported update both rcParams and

~/miniconda3/envs/test/lib/python3.7/site-packages/matplotlib/pyplot.py in switch_backend(newbackend)
    234                 "Cannot load backend {!r} which requires the {!r} interactive "
    235                 "framework, as {!r} is currently running".format(
--> 236                     newbackend, required_framework, current_framework))
    237 
    238     rcParams['backend'] = rcParamsDefault['backend'] = newbackend

ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running

Command or request that led to error:

from rasa.core.interpreter import RegexInterpreter

# or more directly

from rasa.core.test import test
@elyase elyase added the type:bug 🐛 Inconsistencies or issues which will cause an issue or problem for users or implementors. label Oct 22, 2019
@sara-tagger
Copy link
Collaborator

Thanks for the issue, @Ghostvv will get back to you about it soon!

You may find help in the docs and the forum, too 🤗

@tabergma
Copy link
Contributor

@elyase Thanks for raising the issue. In general we are open to making matplotlib optional.

I added the lines back then in rasa/core/test, but cannot remember the exact reason. I just tried to run rasa test nlu (which plots some graphs) without those lines and it was working fine for me. So, I guess we can do as you suggested.

Do you want to clean it up by yourself and create a PR for it?

@stale
Copy link

stale bot commented Jan 22, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the status:stale label Jan 22, 2020
@stale
Copy link

stale bot commented Jan 29, 2020

This issue has been automatically closed due to inactivity. Please create a new issue if you need more help.

@stale stale bot closed this as completed Jan 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:stale type:bug 🐛 Inconsistencies or issues which will cause an issue or problem for users or implementors.
Projects
None yet
Development

No branches or pull requests

3 participants