matplotlib/python的Latex实现问题:运行时错误:找不到Latex命令

2024-09-28 22:05:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在matplotlib图形中为标签使用乳胶。我用的是macosx和thonny。我下载了一个测试程序,但每次都会出错:

RuntimeError: Latex command not found. Install 'xelatex' or change pgf.texsystem to the desired command.

我认为这是一个路径错误。。。在

我也试着改变道路

os.environ["PATH"] += os.pathsep + '/usr/local/texlive/2018/bin/x86_64-darwin'

我得到了这个错误:

kpathsea:make_tex: Invalid filename `DejaVu Serif', contains ' ' /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/init.py:886: MatplotlibDeprecationWarning: examples.directory is deprecated; in the future, examples will be found relative to the 'datapath' directory. "found relative to the 'datapath' directory.".format(key)) /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/init.py:886: MatplotlibDeprecationWarning: examples.directory is deprecated; in the future, examples will be found relative to the 'datapath' directory. "found relative to the 'datapath' directory.".format(key)) /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/init.py:886: MatplotlibDeprecationWarning: examples.directory is deprecated; in the future, examples will be found relative to the 'datapath' directory. "found relative to the 'datapath' directory.".format(key)) /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/init.py:886: MatplotlibDeprecationWarning: examples.directory is deprecated; in the future, examples will be found relative to the 'datapath' directory. "found relative to the 'datapath' directory.".format(key)) /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/init.py:886: MatplotlibDeprecationWarning: examples.directory is deprecated; in the future, examples will be found relative to the 'datapath' directory. "found relative to the 'datapath' directory.".format(key)) /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/init.py:886: MatplotlibDeprecationWarning: examples.directory is deprecated; in the future, examples will be found relative to the 'datapath' directory. "found relative to the 'datapath' directory.".format(key)) /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/init.py:886: MatplotlibDeprecationWarning: examples.directory is deprecated; in the future, examples will be found relative to the 'datapath' directory. "found relative to the 'datapath' directory.".format(key)) /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/init.py:886: MatplotlibDeprecationWarning: examples.directory is deprecated; in the future, examples will be found relative to the 'datapath' directory. "found relative to the 'datapath' directory.".format(key)) /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/init.py:886: MatplotlibDeprecationWarning: examples.directory is deprecated; in the future, examples will be found relative to the 'datapath' directory. "found relative to the 'datapath' directory.".format(key)) Traceback (most recent call last): File "/Users/Marten/Downloads/pgf_preamble_sgskip.py", line 33, in plt.tight_layout(.5) File "/Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/pyplot.py", line 1382, in tight_layout gcf().tight_layout(pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect) File "/Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/figure.py", line 2370, in tight_layout renderer = get_renderer(self) File "/Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/tight_layout.py", line 228, in get_renderer renderer = canvas.get_renderer() File "/Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/backends/backend_pgf.py", line 946, in get_renderer return RendererPgf(self.figure, None, dummy=True) File "/Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/backends/backend_pgf.py", line 393, in init self.latexManager = LatexManagerFactory.get_latex_manager() File "/Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/backends/backend_pgf.py", line 208, in get_latex_manager new_inst = LatexManager() File "/Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/backends/backend_pgf.py", line 290, in init "or error in preamble:\n%s" % stdout) matplotlib.backends.backend_pgf.LatexError: LaTeX returned an error, probably missing font or error in preamble: b'This is XeTeX, Version 3.14159265-2.6-0.99999 (TeX Live 2018) (preloaded format=xelatex)\n restricted \write18 enabled.\n**entering extended mode\nLaTeX2e <2018-04-01> patch level 2\nBabel <3.18> and hyphenation patterns for 84 language(s) loaded.\n\n*(/usr/local/texlive/2018/texmf-dist/tex/latex/base/minimal.cls\nDocument Class: minimal 2001/05/25 Standard LaTeX minimal class\n)\n*(/usr/local/texlive/2018/texmf-dist/tex/latex/units/units.sty\n(/usr/local/texlive/2018/texmf-dist/tex/latex/base/ifthen.sty)\n(/usr/local/texlive/2018/texmf-dist/tex/latex/units/nicefrac.sty))\n*(/usr/local/texlive/2018/texmf-dist/tex/latex/metalogo/metalogo.sty\n(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics/graphicx.sty\n(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics/keyval.sty)\n(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics/graphics.sty\n(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics/trig.sty)\n(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)\n(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics-def/xetex.def)))\n(/usr/local/texlive/2018/texmf-dist/tex/generic/ifxetex/ifxetex.sty)\n(/usr/local/texlive/2018/texmf-dist/tex/latex/fontspec/fontspec.sty\n(/usr/local/texlive/2018/texmf-dist/tex/latex/l3packages/xparse/xparse.sty\n(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/expl3.sty\n(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/expl3-code.tex)\n(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/l3xdvipdfmx.def)))\n(/usr/local/texlive/2018/texmf-dist/tex/latex/fontspec/fontspec-xetex.sty\n(/usr/local/texlive/2018/texmf-dist/tex/latex/base/fontenc.sty\n(/usr/local/texlive/2018/texmf-dist/tex/latex/base/tuenc.def))\n(/usr/local/texlive/2018/texmf-dist/tex/latex/fontspec/fontspec.cfg))))\n*(/usr/local/texlive/2018/texmf-dist/tex/latex/unicode-math/unicode-math.sty\n(/usr/local/texlive/2018/texmf-dist/tex/latex/unicode-math/unicode-math-xetex.s\nty\n(/usr/local/texlive/2018/texmf-dist/tex/latex/l3packages/l3keys2e/l3keys2e.sty)\n (/usr/local/texlive/2018/texmf-dist/tex/latex/filehook/filehook.sty)\n(/usr/local/texlive/2018/texmf-dist/tex/latex/base/fix-cm.sty\n(/usr/local/texlive/2018/texmf-dist/tex/latex/base/ts1enc.def))\n(/usr/local/texlive/2018/texmf-dist/tex/latex/unicode-math/unicode-math-table.t\nex)))\n*\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!\n! fontspec error: "font-not-found"\n! \n! The font "DejaVu Serif" cannot be found.\n! \n! See the fontspec documentation for further information.\n! \n! For immediate help type H .\n!............................................... \n \n<*> \setmainfont{DejaVu Serif}\n \nNo pages of output.\nTranscript written on texput.log.\n'

测试程序:

^{pr2}$

Tags: thetoinmatplotlibusrlocaldistexamples
1条回答
网友
1楼 · 发布于 2024-09-28 22:05:21

因此,我尝试了一个不同的测试程序,其中有plt.rc('text', usetex=True)和{},没有额外的前导码。当我添加路径os.environ["PATH"] += os.pathsep + '/usr/local/texlive/2018/bin/x86_64-darwin'时,这就起作用了。所以问题是以不同的方式解决的。–madden994刚刚编辑

相关问题 更多 >