Python:无法在Matplotlib中渲染Tex

cos*_*sis 34 python matplotlib tex osx-snow-leopard

我最近将我的笔记本电脑升级到Snow Leopard,将TeX更新到版本3.1415926(TeX Live 2011/MacPorts 2011_5),并安装了Python 2.7.3.完成所有这些安装后,我运行了macport selfupdate和macport升级过时.但是,现在当我尝试在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.
Run Code Online (Sandbox Code Playgroud)

前一个问题类似,我尝试通过以下方式在我的python代码中设置路径:

os.environ['PATH'] = os.environ['PATH'] + ':/opt/local/bin/latex'
Run Code Online (Sandbox Code Playgroud)

自从which latex屈服了/opt/local/bin/latex.但是,这不起作用,具有相同的错误消息.我也尝试了tex的路径,以及上一个问题的例子.没变.

然后我尝试通过以下方法强制可能缺少包:

matplotlib.rcParams['text.latex.preamble']=[r"\usepackage{amsmath}"]
Run Code Online (Sandbox Code Playgroud)

然而,这也没有用.

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

Jou*_*nen 41

错误消息显示您错过了type1cm包.似乎MacPorts将其作为其中的一部分texlive-latex-extra.

  • 在Ubuntu 16.04上,需要`texlive-latex-extra`` texlive-fonts-recommended`和`dvipng`. (7认同)
  • 仍适用于我的Ubuntu 13.10机器.我还需要dvipng包. (3认同)
  • 在ubuntu 14.04.1上我需要同时安装`texlive-latex-extra`和`texlive-fonts-recommended` (3认同)
  • 知道在 Windows 机器上添加什么吗?尝试添加 type1cm,它说在 miktex 上找不到包。谢谢 (2认同)

小智 36

我必须将cm-super软件包安装在 ubuntu 衍生物中(源自 Ubuntu 18.04 的jupyter/minimal-notebook$ sudo apt-get install cm-super

  • 事实上,Ubuntu 18.04 需要 `cm-super` 以及 `dvipng` `texlive-latex-extra` `texlive-fonts-recommended`。 (5认同)

小智 31

在Ubunutu 14.04机器上,上述答案的组合起作用.我sudo apt-get installdvipng,texlive-latex-extratexlive-fonts-recommended包和没有的伎俩:

$ sudo apt-get install dvipng texlive-latex-extra texlive-fonts-recommended 
Run Code Online (Sandbox Code Playgroud)

  • 适用于Ubuntu16.04. (4认同)
  • 也适用于 Linux 的 Windows 子系统中的 Ubuntu 16.04.1。 (2认同)