Как использовать шрифты LaTeX в Paperspace Gradient?

#python #matplotlib #latex

#python #matplotlib #Латекс

Вопрос:

Я хочу использовать шрифт LaTeX с графиком matplotlib в записной книжке jupyter в Gradient, но я не могу создать файл latex mplstyle, как в моей локальной системе. Я думаю, проблема в том, что LaTeX не установлен в этой облачной системе. Есть ли способ установить LaTeX на облачной платформе? Это ошибка, которую я получаю, когда пытаюсь изменить параметр mlpstyle matplotlib для использования tex и построить свою диаграмму с помощью шрифтов latex.

 
    FileNotFoundError                         Traceback (most recent call last) /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/texmanager.py in _run_checked_subprocess(self, command, tex)
            274         try:
        --> 275             report = subprocess.check_output(command,
            276                                              cwd=self.texcache,
        
        /opt/conda/envs/fastai/lib/python3.8/subprocess.py in check_output(timeout, *popenargs, **kwargs)
            410 
        --> 411     return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
            412                **kwargs).stdout
        
        /opt/conda/envs/fastai/lib/python3.8/subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
            488 
        --> 489     with Popen(*popenargs, **kwargs) as process:
            490         try:
        
        /opt/conda/envs/fastai/lib/python3.8/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
            853 
        --> 854             self._execute_child(args, executable, preexec_fn, close_fds,
            855                                 pass_fds, cwd, env,
        
        /opt/conda/envs/fastai/lib/python3.8/subprocess.py in
        _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)    1701                         err_msg = os.strerror(errno_num)
        -> 1702                     raise child_exception_type(errno_num, err_msg, err_filename)    1703                 raise child_exception_type(err_msg)
        
        FileNotFoundError: [Errno 2] No such file or directory: 'latex'
        
        The above exception was the direct cause of the following exception:
        
        RuntimeError                              Traceback (most recent call last) <ipython-input-45-1b9c79a562c2> in <module>
              4 plt.ylabel('Loss', fontsize=20)
              5 plt.legend(fontsize=10)
        ----> 6 fig256.savefig('what.pdf', dpi=400, bbox_inches='tight')
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/figure.py in savefig(self, fname, transparent, **kwargs)    2309                 patch.set_edgecolor('none')    2310 
        -> 2311         self.canvas.print_figure(fname, **kwargs)    2312     2313         if transparent:
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)    2191                            else suppress()) 2192                     with ctx:
        -> 2193                         self.figure.draw(renderer)    2194     2195                     bbox_inches = self.figure.get_tightbbox(
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
             39                 renderer.start_filter()
             40 
        ---> 41             return draw(artist, renderer, *args, **kwargs)
             42         finally:
             43             if artist.get_agg_filter() is not None:
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/figure.py in draw(self, renderer)    1861     1862             self.patch.draw(renderer)
        -> 1863             mimage._draw_list_compositing_images(    1864                 renderer, self, artists, self.suppressComposite)    1865 
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
            129     if not_composite or not has_images:
            130         for a in artists:
        --> 131             a.draw(renderer)
            132     else:
            133         # Composite any adjacent images together
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
             39                 renderer.start_filter()
             40 
        ---> 41             return draw(artist, renderer, *args, **kwargs)
             42         finally:
             43             if artist.get_agg_filter() is not None:
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/cbook/deprecation.py in wrapper(*inner_args, **inner_kwargs)
            409                          else deprecation_addendum,
            410                 **kwargs)
        --> 411         return func(*inner_args, **inner_kwargs)
            412 
            413     return wrapper
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)    2746             renderer.stop_rasterizing()    2747 
        -> 2748         mimage._draw_list_compositing_images(renderer, self, artists)    2749     2750         renderer.close_group('axes')
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
            129     if not_composite or not has_images:
            130         for a in artists:
        --> 131             a.draw(renderer)
            132     else:
            133         # Composite any adjacent images together
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
             39                 renderer.start_filter()
             40 
        ---> 41             return draw(artist, renderer, *args, **kwargs)
             42         finally:
             43             if artist.get_agg_filter() is not None:
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/axis.py in draw(self, renderer, *args, **kwargs)    1163     1164         ticks_to_draw = self._update_ticks()
        -> 1165         ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,    1166                           renderer)    1167 
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/axis.py in _get_tick_bboxes(self, ticks, renderer)    1089     def
        _get_tick_bboxes(self, ticks, renderer):    1090         """Return lists of bboxes for ticks' label1's and label2's."""
        -> 1091         return ([tick.label1.get_window_extent(renderer)    1092                  for tick in ticks if tick.label1.get_visible()], 1093                 [tick.label2.get_window_extent(renderer)
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/axis.py in <listcomp>(.0)    1089     def _get_tick_bboxes(self, ticks, renderer):    1090         """Return lists of bboxes for ticks' label1's and label2's."""
        -> 1091         return ([tick.label1.get_window_extent(renderer)    1092                  for tick in ticks if tick.label1.get_visible()], 1093                 [tick.label2.get_window_extent(renderer)
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/text.py in get_window_extent(self, renderer, dpi)
            898 
            899         with cbook._setattr_cm(self.figure, dpi=dpi):
        --> 900             bbox, info, descent = self._get_layout(self._renderer)
            901             x, y = self.get_unitless_position()
            902             x, y = self.get_transform().transform((x, y))
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/text.py in _get_layout(self, renderer)
            283 
            284         # Full vertical extent of font, including ascenders and descenders:
        --> 285         _, lp_h, lp_d = renderer.get_text_width_height_descent(
            286             "lp", self._fontproperties,
            287             ismath="TeX" if self.get_usetex() else False)
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/backends/_backend_pdf_ps.py in get_text_width_height_descent(self, s, prop, ismath)
             84             texmanager = self.get_texmanager()
             85             fontsize = prop.get_size_in_points()
        ---> 86             w, h, d = texmanager.get_text_width_height_descent(
             87                 s, fontsize, renderer=self)
             88             return w, h, d
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/texmanager.py in get_text_width_height_descent(self, tex, fontsize, renderer)
            421         else:
            422             # use dviread.
        --> 423             dvifile = self.make_dvi(tex, fontsize)
            424             with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:
            425                 page, = dvi
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/texmanager.py in make_dvi(self, tex, fontsize)
            307             texfile = self.make_tex(tex, fontsize)
            308             with cbook._lock_path(texfile):
        --> 309                 self._run_checked_subprocess(
            310                     ["latex", "-interaction=nonstopmode", "--halt-on-error",
            311                      texfile], tex)
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/texmanager.py in _run_checked_subprocess(self, command, tex)
            277                                              stderr=subprocess.STDOUT)
            278         except FileNotFoundError as exc:
        --> 279             raise RuntimeError(
            280                 'Failed to process string with tex because {} could not be '
            281                 'found'.format(command[0])) from exc
        
        RuntimeError: Failed to process string with tex because latex could not be found
        
        --------------------------------------------------------------------------- FileNotFoundError                         Traceback (most recent call last) /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/texmanager.py in _run_checked_subprocess(self, command, tex)
            274         try:
        --> 275             report = subprocess.check_output(command,
            276                                              cwd=self.texcache,
        
        /opt/conda/envs/fastai/lib/python3.8/subprocess.py in check_output(timeout, *popenargs, **kwargs)
            410 
        --> 411     return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
            412                **kwargs).stdout
        
        /opt/conda/envs/fastai/lib/python3.8/subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
            488 
        --> 489     with Popen(*popenargs, **kwargs) as process:
            490         try:
        
        /opt/conda/envs/fastai/lib/python3.8/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
            853 
        --> 854             self._execute_child(args, executable, preexec_fn, close_fds,
            855                                 pass_fds, cwd, env,
        
        /opt/conda/envs/fastai/lib/python3.8/subprocess.py in
        _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)    1701                         err_msg = os.strerror(errno_num)
        -> 1702                     raise child_exception_type(errno_num, err_msg, err_filename)    1703                 raise child_exception_type(err_msg)
        
        FileNotFoundError: [Errno 2] No such file or directory: 'latex'
        
        The above exception was the direct cause of the following exception:
        
        RuntimeError                              Traceback (most recent call last) /opt/conda/envs/fastai/lib/python3.8/site-packages/IPython/core/formatters.py in __call__(self, obj)
            339                 pass
            340             else:
        --> 341                 return printer(obj)
            342             # Finally look for special method names
            343             method = get_real_method(obj, self.print_method)
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/IPython/core/pylabtools.py in <lambda>(fig)
            246 
            247     if 'png' in formats:
        --> 248         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
            249     if 'retina' in formats or 'png2x' in formats:
            250         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
            130         FigureCanvasBase(fig)
            131 
        --> 132     fig.canvas.print_figure(bytes_io, **kw)
            133     data = bytes_io.getvalue()
            134     if fmt == 'svg':
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)    2191                            else suppress()) 2192                     with ctx:
        -> 2193                         self.figure.draw(renderer)    2194     2195                     bbox_inches = self.figure.get_tightbbox(
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
             39                 renderer.start_filter()
             40 
        ---> 41             return draw(artist, renderer, *args, **kwargs)
             42         finally:
             43             if artist.get_agg_filter() is not None:
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/figure.py in draw(self, renderer)    1861     1862             self.patch.draw(renderer)
        -> 1863             mimage._draw_list_compositing_images(    1864                 renderer, self, artists, self.suppressComposite)    1865 
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
            129     if not_composite or not has_images:
            130         for a in artists:
        --> 131             a.draw(renderer)
            132     else:
            133         # Composite any adjacent images together
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
             39                 renderer.start_filter()
             40 
        ---> 41             return draw(artist, renderer, *args, **kwargs)
             42         finally:
             43             if artist.get_agg_filter() is not None:
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/cbook/deprecation.py in wrapper(*inner_args, **inner_kwargs)
            409                          else deprecation_addendum,
            410                 **kwargs)
        --> 411         return func(*inner_args, **inner_kwargs)
            412 
            413     return wrapper
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)    2746             renderer.stop_rasterizing()    2747 
        -> 2748         mimage._draw_list_compositing_images(renderer, self, artists)    2749     2750         renderer.close_group('axes')
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
            129     if not_composite or not has_images:
            130         for a in artists:
        --> 131             a.draw(renderer)
            132     else:
            133         # Composite any adjacent images together
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
             39                 renderer.start_filter()
             40 
        ---> 41             return draw(artist, renderer, *args, **kwargs)
             42         finally:
             43             if artist.get_agg_filter() is not None:
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/axis.py in draw(self, renderer, *args, **kwargs)    1163     1164         ticks_to_draw = self._update_ticks()
        -> 1165         ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,    1166                           renderer)    1167 
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/axis.py in _get_tick_bboxes(self, ticks, renderer)    1089     def
        _get_tick_bboxes(self, ticks, renderer):    1090         """Return lists of bboxes for ticks' label1's and label2's."""
        -> 1091         return ([tick.label1.get_window_extent(renderer)    1092                  for tick in ticks if tick.label1.get_visible()], 1093                 [tick.label2.get_window_extent(renderer)
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/axis.py in <listcomp>(.0)    1089     def _get_tick_bboxes(self, ticks, renderer):    1090         """Return lists of bboxes for ticks' label1's and label2's."""
        -> 1091         return ([tick.label1.get_window_extent(renderer)    1092                  for tick in ticks if tick.label1.get_visible()], 1093                 [tick.label2.get_window_extent(renderer)
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/text.py in get_window_extent(self, renderer, dpi)
            898 
            899         with cbook._setattr_cm(self.figure, dpi=dpi):
        --> 900             bbox, info, descent = self._get_layout(self._renderer)
            901             x, y = self.get_unitless_position()
            902             x, y = self.get_transform().transform((x, y))
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/text.py in _get_layout(self, renderer)
            283 
            284         # Full vertical extent of font, including ascenders and descenders:
        --> 285         _, lp_h, lp_d = renderer.get_text_width_height_descent(
            286             "lp", self._fontproperties,
            287             ismath="TeX" if self.get_usetex() else False)
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in get_text_width_height_descent(self, s, prop, ismath)
            225             texmanager = self.get_texmanager()
            226             fontsize = prop.get_size_in_points()
        --> 227             w, h, d = texmanager.get_text_width_height_descent(
            228                 s, fontsize, renderer=self)
            229             return w, h, d
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/texmanager.py in get_text_width_height_descent(self, tex, fontsize, renderer)
            421         else:
            422             # use dviread.
        --> 423             dvifile = self.make_dvi(tex, fontsize)
            424             with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:
            425                 page, = dvi
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/texmanager.py in make_dvi(self, tex, fontsize)
            307             texfile = self.make_tex(tex, fontsize)
            308             with cbook._lock_path(texfile):
        --> 309                 self._run_checked_subprocess(
            310                     ["latex", "-interaction=nonstopmode", "--halt-on-error",
            311                      texfile], tex)
        
        /opt/conda/envs/fastai/lib/python3.8/site-packages/matplotlib/texmanager.py in _run_checked_subprocess(self, command, tex)
            277                                              stderr=subprocess.STDOUT)
            278         except FileNotFoundError as exc:
        --> 279             raise RuntimeError(
            280                 'Failed to process string with tex because {} could not be '
            281                 'found'.format(command[0])) from exc
        
        RuntimeError: Failed to process string with tex because latex could not be found
        
        <Figure size 576x396 with 1 Axes>
'''

Does somebody know a workaround?
  

Комментарии:

1. что такое градиент?

2. Облачная платформа с ускорением GPU для машинного обучения

3. Установлен ли на нем latex?

4. Я думаю, что это проблема. Есть ли способ установить LaTeX в облачной системе? Я добавил ошибку, отображаемую при попытке построения графика в моем вопросе

5. Я думаю, что это заслуживает отдельного вопроса, специфичного для продукта Gradient