data-8 / Gofer-Grader

Small autograding library
http://okgrade.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
16 stars 19 forks source link

Issue with Matplotlib 2.2.3 conflict. #11

Closed jkuruzovich closed 5 years ago

jkuruzovich commented 6 years ago

I was able to successfully use this for a few class exercises but now have run into an issue.

(I know you explicitly said don't rely upon but I really like how Okpy client works and this seems to be working and wanted to give it a shot. )

If matplotlib is not installed: (1) Tests run fine.

If matplotlib is installed: (1) Tests run fine. (2) after importing pandas all tests result in the following error:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-3-0157b017ef8a> in <module>()
----> 1 _ = ok.grade('q02')

/anaconda3/envs/grademe/lib/python3.6/site-packages/client/api/notebook.py in grade(self, question, global_env)
     56             # inspect trick to pass in its parents' global env.
     57             global_env = inspect.currentframe().f_back.f_globals
---> 58         result = check(path, global_env)
     59         # We display the output if we're in IPython.
     60         # This keeps backwards compatibility with okpy's grade method

/anaconda3/envs/grademe/lib/python3.6/site-packages/gradememaybe/ok.py in check(test_file_path, global_env)
    243         # inspect trick to pass in its parents' global env.
    244         global_env = inspect.currentframe().f_back.f_globals
--> 245     return tests.run(global_env, include_grade=False)

/anaconda3/envs/grademe/lib/python3.6/site-packages/gradememaybe/ok.py in run(self, global_environment, include_grade)
    138         failed_tests = []
    139         for t in self.tests:
--> 140             passed, hint = t.run(global_environment)
    141             if passed:
    142                 passed_tests.append(t)

/anaconda3/envs/grademe/lib/python3.6/site-packages/gradememaybe/ok.py in run(self, global_environment)
     81     def run(self, global_environment):
     82         for i, t in enumerate(self.tests):
---> 83             passed, result = run_doctest(self.name + ' ' + str(i), t, global_environment)
     84             if not passed:
     85                 return False, OKTest.result_fail_template.render(

/anaconda3/envs/grademe/lib/python3.6/site-packages/gradememaybe/ok.py in run_doctest(name, doctest_string, global_environment)
     39     runresults = io.StringIO()
     40     with redirect_stdout(runresults), redirect_stderr(runresults), hide_outputs():
---> 41         doctestrunner.run(test, clear_globs=False)
     42     with open('/dev/null', 'w') as f, redirect_stderr(f), redirect_stdout(f):
     43         result = doctestrunner.summarize(verbose=True)

/anaconda3/envs/grademe/lib/python3.6/contextlib.py in __exit__(self, type, value, traceback)
     86         if type is None:
     87             try:
---> 88                 next(self.gen)
     89             except StopIteration:
     90                 return False

/anaconda3/envs/grademe/lib/python3.6/site-packages/gradememaybe/utils.py in hide_outputs()
     46         yield
     47     finally:
---> 48         flush_inline_matplotlib_plots()
     49         ipy.display_formatter.formatters = old_formatters

/anaconda3/envs/grademe/lib/python3.6/site-packages/gradememaybe/utils.py in flush_inline_matplotlib_plots()
     21     try:
     22         import matplotlib as mpl
---> 23         from ipykernel.pylab.backend_inline import flush_figures
     24     except ImportError:
     25         return

/anaconda3/envs/grademe/lib/python3.6/site-packages/ipykernel/pylab/backend_inline.py in <module>()
    167             ip.events.register('post_run_cell', configure_once)
    168 
--> 169 _enable_matplotlib_integration()
    170 
    171 def _fetch_figure_metadata(fig):

/anaconda3/envs/grademe/lib/python3.6/site-packages/ipykernel/pylab/backend_inline.py in _enable_matplotlib_integration()
    158         try:
    159             activate_matplotlib(backend)
--> 160             configure_inline_support(ip, backend)
    161         except (ImportError, AttributeError):
    162             # bugs may cause a circular import on Python 2

/anaconda3/envs/grademe/lib/python3.6/site-packages/IPython/core/pylabtools.py in configure_inline_support(shell, backend)
    409     if new_backend_name != cur_backend:
    410         # Setup the default figure format
--> 411         select_figure_formats(shell, cfg.figure_formats, **cfg.print_figure_kwargs)
    412         configure_inline_support.current_backend = new_backend_name

/anaconda3/envs/grademe/lib/python3.6/site-packages/IPython/core/pylabtools.py in select_figure_formats(shell, formats, **kwargs)
    215     from matplotlib.figure import Figure
    216 
--> 217     svg_formatter = shell.display_formatter.formatters['image/svg+xml']
    218     png_formatter = shell.display_formatter.formatters['image/png']
    219     jpg_formatter = shell.display_formatter.formatters['image/jpeg']

KeyError: 'image/svg+xml'

Uninstalling matplotlib seems to work.

jkuruzovich commented 5 years ago

This seems to have been fixed this year. Working well on a colab environment.

matthew-brett commented 5 years ago

I have this issue too:

on Homebrew Python.

matthew-brett commented 5 years ago

Oops - sorry - it looks like I have #23. I'll comment there.