Python:无法在Matplotlib中呈现Tex

2024-09-28 17:30:14 发布

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

我最近把我的笔记本升级到雪豹,把TeX升级到3.1415926版本(TeX Live 2011/macports2011_5),并安装了Python 2.7.3。在所有这些安装之后,我运行了macport selfupdate和macport upgrade deposited。但是,现在当我尝试在matplotlib中使用TeX时,会收到以下消息:

LaTeX was not able to process the following string:'lp'
Here is the full report generated by LaTeX: 

This is pdfTeX, Version 3.1415926-2.3-1.40.12 (TeX Live 2011/MacPorts 2011_5)
 restricted \write18 enabled.  
entering extended mode (./64a53cc27244d5ee10969789771e33fa.tex
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, dumylang, nohyphenation, cz
ech, slovak, dutch, ukenglish, usenglishmax, basque, french, german-x-2009-06-1
9, ngerman-x-2009-06-19, german, ngerman, swissgerman, italian, polish, portugu
ese, spanish, catalan, galician, ukenglish, loaded.
(/opt/local/share/texmf-texlive-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/opt/local/share/texmf-texlive-dist/tex/latex/base/size10.clo))

! LaTeX Error: File `type1cm.sty' not found.

Type X to quit or <RETURN> to proceed, or enter new name. (Default extension: sty)


l.3 \renewcommand
             {\rmdefault}{pnc}^^M
No pages of output.

this previous question类似,我尝试通过以下方式在python代码中设置路径:

os.environ['PATH'] = os.environ['PATH'] + ':/opt/local/bin/latex'

因为which latex产生了/opt/local/bin/latex。但是,这不起作用,错误信息相同。我还尝试了tex的路径,以及上一个问题中的示例。没有变化。

然后我试图通过以下方式强制可能丢失的包:

matplotlib.rcParams['text.latex.preamble']=[r"\usepackage{amsmath}"]

然而,这也不起作用。

唯一能让我的情节发挥作用的方法就是说rc('text', usetex=False),这并不理想。任何帮助都将不胜感激。


Tags: thetolivematplotlibislocalnotlatex
2条回答

错误消息说您缺少type1cm包。好像是MacPorts includes it as part of ^{}

在Ubunutu 14.04机器上,上面的答案组合起作用。我sudo apt-get installdvipngtexlive-latex-extra,和texlive-fonts-recommended包,这就做到了:

$ sudo apt-get install dvipng texlive-latex-extra texlive-fonts-recommended 

相关问题 更多 >