RuntimeError:由于找不到乳胶,无法使用tex处理字符串 [英] RuntimeError: Failed to process string with tex because latex could not be found

查看:136
本文介绍了RuntimeError:由于找不到乳胶,无法使用tex处理字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 Matplotlib 中使用 LaTeX 渲染文本.Matplotlib在 https://matplotlib.org/3.1.1提供了一个演示./gallery/text_labels_and_annotations/tex_demo.html.

I was trying to render text with LaTeX in Matplotlib. There is a demo provided by Matplotlib at https://matplotlib.org/3.1.1/gallery/text_labels_and_annotations/tex_demo.html.

但是,当我运行此演示时,出现此错误,提示"RuntimeError:由于找不到乳胶,无法使用tex处理字符串",但是我确定我已经安装了Matlibplot所需的Miktex和Ghostscript.

However, when I ran this demo, I got this error saying "RuntimeError: Failed to process string with tex because latex could not be found", but I'm sure I have installed Miktex and Ghostscript required by Matlibplot.

任何人都知道我应该如何解决?谢谢.

Anyone knows how should I solve it? Thanks.

import numpy as np
import matplotlib
matplotlib.rcParams['text.usetex'] = True
import matplotlib.pyplot as plt


t = np.linspace(0.0, 1.0, 100)
s = np.cos(4 * np.pi * t) + 2

fig, ax = plt.subplots(figsize=(6, 4), tight_layout=True)
ax.plot(t, s)

ax.set_xlabel(r'\textbf{time (s)}')
ax.set_ylabel('\\textit{Velocity (\N{DEGREE SIGN}/sec)}', fontsize=16)
ax.set_title(r'\TeX\ is Number $\displaystyle\sum_{n=1}^\infty'
             r'\frac{-e^{i\pi}}{2^n}$!', fontsize=16, color='r')
plt.show()

这是错误回溯:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\texmanager.py", line 304, in _run_checked_subprocess
    stderr=subprocess.STDOUT)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\subprocess.py", line 336, in check_output
    **kwargs).stdout
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\subprocess.py", line 403, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\subprocess.py", line 997, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The System Cannot Find the File Specified
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\tkinter\__init__.py", line 1702, in __call__
    return self.func(*args)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\tkinter\__init__.py", line 746, in callit
    func(*args)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\backends\_backend_tk.py", line 338, in idle_draw
    self.draw()
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 9, in draw
    super(FigureCanvasTkAgg, self).draw()
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\backends\backend_agg.py", line 388, in draw
    self.figure.draw(self.renderer)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\figure.py", line 1702, in draw
    **self._tight_parameters)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\figure.py", line 2476, in tight_layout
    pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\tight_layout.py", line 362, in get_tight_layout_figure
    pad=pad, h_pad=h_pad, w_pad=w_pad)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\tight_layout.py", line 111, in auto_adjust_subplotpars
    tight_bbox_raw = union([ax.get_tightbbox(renderer) for ax in subplots
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\tight_layout.py", line 112, in <listcomp>
    if ax.get_visible()])
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\axes\_base.py", line 4355, in get_tightbbox
    bb_xaxis = self.xaxis.get_tightbbox(renderer)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\axis.py", line 1164, in get_tightbbox
    self._update_label_position(renderer)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\axis.py", line 2014, in _update_label_position
    bboxes, bboxes2 = self._get_tick_boxes_siblings(renderer=renderer)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\axis.py", line 1999, in _get_tick_boxes_siblings
    tlb, tlb2 = axx.xaxis._get_tick_bboxes(ticks_to_draw, renderer)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\axis.py", line 1150, in _get_tick_bboxes
    for tick in ticks if tick.label1.get_visible()],
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\axis.py", line 1150, in <listcomp>
    for tick in ticks if tick.label1.get_visible()],
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\text.py", line 890, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\text.py", line 291, in _get_layout
    ismath="TeX" if self.get_usetex() else False)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\backends\backend_agg.py", line 201, in get_text_width_height_descent
    s, fontsize, renderer=self)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\texmanager.py", line 448, in get_text_width_height_descent
    dvifile = self.make_dvi(tex, fontsize)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\texmanager.py", line 338, in make_dvi
    texfile], tex)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\texmanager.py", line 308, in _run_checked_subprocess
    'found'.format(command[0])) from exc
RuntimeError: Failed to process string with tex because latex could not be found
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\texmanager.py", line 304, in _run_checked_subprocess
    stderr=subprocess.STDOUT)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\subprocess.py", line 336, in check_output
    **kwargs).stdout
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\subprocess.py", line 403, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\subprocess.py", line 997, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The System Cannot Find the File Specified
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\tkinter\__init__.py", line 1702, in __call__
    return self.func(*args)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\backends\_backend_tk.py", line 259, in resize
    self.draw()
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 9, in draw
    super(FigureCanvasTkAgg, self).draw()
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\backends\backend_agg.py", line 388, in draw
    self.figure.draw(self.renderer)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\figure.py", line 1702, in draw
    **self._tight_parameters)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\figure.py", line 2476, in tight_layout
    pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\tight_layout.py", line 362, in get_tight_layout_figure
    pad=pad, h_pad=h_pad, w_pad=w_pad)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\tight_layout.py", line 111, in auto_adjust_subplotpars
    tight_bbox_raw = union([ax.get_tightbbox(renderer) for ax in subplots
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\tight_layout.py", line 112, in <listcomp>
    if ax.get_visible()])
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\axes\_base.py", line 4355, in get_tightbbox
    bb_xaxis = self.xaxis.get_tightbbox(renderer)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\axis.py", line 1164, in get_tightbbox
    self._update_label_position(renderer)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\axis.py", line 2014, in _update_label_position
    bboxes, bboxes2 = self._get_tick_boxes_siblings(renderer=renderer)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\axis.py", line 1999, in _get_tick_boxes_siblings
    tlb, tlb2 = axx.xaxis._get_tick_bboxes(ticks_to_draw, renderer)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\axis.py", line 1150, in _get_tick_bboxes
    for tick in ticks if tick.label1.get_visible()],
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\axis.py", line 1150, in <listcomp>
    for tick in ticks if tick.label1.get_visible()],
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\text.py", line 890, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\text.py", line 291, in _get_layout
    ismath="TeX" if self.get_usetex() else False)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\backends\backend_agg.py", line 201, in get_text_width_height_descent
    s, fontsize, renderer=self)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\texmanager.py", line 448, in get_text_width_height_descent
    dvifile = self.make_dvi(tex, fontsize)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\texmanager.py", line 338, in make_dvi
    texfile], tex)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\texmanager.py", line 308, in _run_checked_subprocess
    'found'.format(command[0])) from exc
RuntimeError: Failed to process string with tex because latex could not be found
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\texmanager.py", line 304, in _run_checked_subprocess
    stderr=subprocess.STDOUT)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\subprocess.py", line 336, in check_output
    **kwargs).stdout
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\subprocess.py", line 403, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\subprocess.py", line 997, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The System Cannot Find the File Specified

Traceback (most recent call last):
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\tkinter\__init__.py", line 1702, in __call__
    return self.func(*args)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\tkinter\__init__.py", line 746, in callit
    func(*args)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\backends\_backend_tk.py", line 338, in idle_draw
    self.draw()
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 9, in draw
    super(FigureCanvasTkAgg, self).draw()
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\backends\backend_agg.py", line 388, in draw
    self.figure.draw(self.renderer)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\figure.py", line 1702, in draw
    **self._tight_parameters)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\figure.py", line 2476, in tight_layout
    pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\tight_layout.py", line 362, in get_tight_layout_figure
    pad=pad, h_pad=h_pad, w_pad=w_pad)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\tight_layout.py", line 111, in auto_adjust_subplotpars
    tight_bbox_raw = union([ax.get_tightbbox(renderer) for ax in subplots
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\tight_layout.py", line 112, in <listcomp>
    if ax.get_visible()])
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\axes\_base.py", line 4355, in get_tightbbox
    bb_xaxis = self.xaxis.get_tightbbox(renderer)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\axis.py", line 1164, in get_tightbbox
    self._update_label_position(renderer)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\axis.py", line 2014, in _update_label_position
    bboxes, bboxes2 = self._get_tick_boxes_siblings(renderer=renderer)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\axis.py", line 1999, in _get_tick_boxes_siblings
    tlb, tlb2 = axx.xaxis._get_tick_bboxes(ticks_to_draw, renderer)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\axis.py", line 1150, in _get_tick_bboxes
    for tick in ticks if tick.label1.get_visible()],
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\axis.py", line 1150, in <listcomp>
    for tick in ticks if tick.label1.get_visible()],
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\text.py", line 890, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\text.py", line 291, in _get_layout
    ismath="TeX" if self.get_usetex() else False)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\backends\backend_agg.py", line 201, in get_text_width_height_descent
    s, fontsize, renderer=self)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\texmanager.py", line 448, in get_text_width_height_descent
    dvifile = self.make_dvi(tex, fontsize)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\texmanager.py", line 338, in make_dvi
    texfile], tex)
  File "C:\Users\haiqing\Anaconda3\envs\mie324\lib\site-packages\matplotlib\texmanager.py", line 308, in _run_checked_subprocess
    'found'.format(command[0])) from exc
RuntimeError: Failed to process string with tex because latex could not be found

推荐答案

根据 matplotlib 文档:

Matplotlib的LaTeX支持需要有效的LaTeX安装,dvipng(它可能包含在LaTeX安装中)和Ghostscript(需要GPL Ghostscript 9.0或更高版本).这些外部依赖项的可执行文件必须全部位于PATH中.

Matplotlib's LaTeX support requires a working LaTeX installation, dvipng (which may be included with your LaTeX installation), and Ghostscript (GPL Ghostscript 9.0 or later is required). The executables for these external dependencies must all be located on your PATH.

如果您不熟悉 PATH ,则意味着这些程序的 .exe 文件必须位于系统环境变量中.在Windows中,编辑系统环境变量,单击变量 Path ,然后将上述程序的文件路径添加到列表中.

If you're not familiar with PATH, this means that the .exe files of these programs need to be in your system environment variables. In Windows, Edit the System Environment Variables, click on variable Path, and add the filepaths of the aforementioned programs to the list.

这篇关于RuntimeError:由于找不到乳胶,无法使用tex处理字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆