簡體   English   中英

matplotlib/python 的 Latex 實現問題:RuntimeError:未找到 Latex 命令

[英]Latex implementation problem with matplotlib/python: RuntimeError: Latex command not found

我想在我的 matplotlib 圖形中為我的標簽使用乳膠。 我正在使用 Mac OS X 和 thonny。 我下載了一個測試程序,但每次出現錯誤時:

運行時錯誤:未找到 Latex 命令。 安裝 'xelatex' 或將 pgf.texsystem 更改為所需的命令。

我認為這是一個路徑錯誤...

我也試圖改變路徑

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

我收到此錯誤:

kpathsea:make_tex: 無效的文件名 `DejaVu Serif',包含 '' /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/ init .py:886: MatplotlibDeprecationWarning: examples.directory 被棄用; 將來,將找到與“datapath”目錄相關的示例。 “找到相對於‘數據路徑’目錄。”.format(key)) /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/ init .py:886: MatplotlibDeprecationWarning: examples.directory 是已棄用; 將來,將找到與“datapath”目錄相關的示例。 “找到相對於‘數據路徑’目錄。”.format(key)) /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/ init .py:886: MatplotlibDeprecationWarning: examples.directory 是已棄用; 將來,將找到與“datapath”目錄相關的示例。 “找到相對於‘數據路徑’目錄。”.format(key)) /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/ init .py:886: MatplotlibDeprecationWarning: examples.directory 是已棄用; 將來,將找到與“datapath”目錄相關的示例。 “找到相對於‘數據路徑’目錄。”.format(key)) /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/ init .py:886: MatplotlibDeprecationWarning: examples.directory 是已棄用; 將來,將找到與“datapath”目錄相關的示例。 “找到相對於‘數據路徑’目錄。”.format(key)) /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/ init .py:886: MatplotlibDeprecationWarning: examples.directory 是已棄用; 將來,將找到與“datapath”目錄相關的示例。 “找到相對於‘數據路徑’目錄。”.format(key)) /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/ init .py:886: MatplotlibDeprecationWarning: examples.directory 是已棄用; 將來,將找到與“datapath”目錄相關的示例。 “找到相對於‘數據路徑’目錄。”.format(key)) /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/ init .py:886: MatplotlibDeprecationWarning: examples.directory 是已棄用; 將來,將找到與“datapath”目錄相關的示例。 “找到相對於‘數據路徑’目錄。”.format(key)) /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/ init .py:886: MatplotlibDeprecationWarning: examples.directory 是已棄用; 將來,將找到與“datapath”目錄相關的示例。 “找到相對於‘數據路徑’目錄。”.format(key)) 回溯(最近一次調用最后一次):文件“/Users/Marten/Downloads/pgf_preamble_sgskip.py”,第 33 行,在 plt.tight_layout(.5) 中文件“/Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/pyplot.py”,第1382行,在tight_layout gcf().tight_layout(pad=pad, h_pad=h_pad, w_pad=w_pad , rect=rect) 文件 "/Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/figure.py", line 2370, in tiny_layout renderer = get_renderer(self) File "/Users/Marten /Library/Python/3.7/lib/python/site-packages/matplotlib/tight_layout.py”,第 228 行,在 get_renderer 渲染器 = canvas.get_renderer() 文件“/Users/Marten/Library/Python/3.7/lib/python /site-packages/matplotlib/backends/backend_pgf.py”,第 946 行,在 get_renderer 中返回 RendererPgf(self.figure, None, dummy=True) 文件“/Users/Marten/Library/Python/3.7/lib/python/site -packages/matplotlib/backends/backend_pgf.py”,第 393 行,在init self.latexManager = LatexManagerFactory.get_lat ex_manager() 文件“/Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/backends/backend_pgf.py”,第 208 行,在 get_latex_manager new_inst = LatexManager() 文件“/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 返回錯誤,可能缺少字體或序言中的錯誤:b'This is XeTeX, Version 3.14159265-2.6-0.99999 (TeX Live 2018) (preloaded format=xelatex)\\n 已啟用受限\\write18。\\n**進入擴展模式\\nLaTeX2e <2018-04-01> 補丁級別 2\\nBabel <3.18> 和 84 種語言的斷字模式已加載。\\n\\n*(/usr/local/texlive/2018/texmf-dist/tex/latex /base/minimal.cls\\n文檔類:最小 2001/05/25 標准 LaTeX 最小類\\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/fontspec/fontspec.sty) /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/fonts pec-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!\\啊! fontspec 錯誤:“找不到字體”\\n! \\n! 找不到字體“DejaVu Serif”。​​\\n! \\n! 有關詳細信息,請參閱 fontspec 文檔。\\n! \\n! 如需即時幫助,請輸入 H .\\n!................................................ ...... \\n \\n<*> \\setmainfont{DejaVu Serif}\\n \\n沒有輸出頁面。\\n文本寫在 texput.log 上。\\n'

測試程序:

import matplotlib as mpl
mpl.use("pgf")
import matplotlib.pyplot as plt
import os
os.environ["PATH"] += os.pathsep + '/usr/local/texlive/2018/bin/x86_64-darwin'

plt.rcParams.update({
    "font.family": "serif",  # use serif/main font for text elements
    "text.usetex": True,     # use inline math for ticks
    "pgf.rcfonts": False,    # don't setup fonts from rc parameters
    "pgf.texsystem" : "xelatex",
    "pgf.preamble": [
         "\\usepackage{units}",          # load additional packages
         "\\usepackage{metalogo}",
         "\\usepackage{unicode-math}",   # unicode math setup
         r"\setmathfont{xits-math.otf}",
         r"\setmainfont{DejaVu Serif}",  # serif font via preamble
         ]
})

plt.figure(figsize=(4.5, 2.5))
plt.plot(range(5))
plt.xlabel("unicode text: я, ψ, €, ü, \\unitfrac[10]{°}{µm}")
plt.ylabel("\\XeLaTeX")
plt.legend(["unicode math: $λ=∑_i^∞ μ_i^2$"])
plt.tight_layout(.5)

plt.savefig("pgf_preamble.pdf")
plt.savefig("pgf_preamble.png")

所以我用plt.rc('text', usetex=True)plt.rc('font', family='serif')嘗試了一個不同的測試程序,沒有額外的序言。 當我添加路徑os.environ["PATH"] += os.pathsep + '/usr/local/texlive/2018/bin/x86_64-darwin'時,這會起作用。 所以問題以不同的方式解決。 – madden994 剛剛編輯

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM