Minted 错误:缺少 pygments 错误

Minted 错误:缺少 pygments 错误

我已经安装了 minted 包并在 TexWorks 的设置中插入了 --shell-escape 命令。

\documentclass{article}
\usepackage{minted}


\begin{document}
\begin{minted}{python}
import nump as np
\end{minted}
\end{document}

这是控制台输出。

This is pdfTeX, Version 3.14159265-2.6-1.40.17 (MiKTeX 2.9.6210 64-bit)
entering extended mode
(untitled-2.tex
LaTeX2e <2017/01/01> patch level 1
Babel <3.9r> and hyphenation patterns for 75 language(s) loaded.
("C:\Program Files\MiKTeX 2.9\tex\latex\base\article.cls"
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
("C:\Program Files\MiKTeX 2.9\tex\latex\base\size10.clo"))
("C:\Program Files\MiKTeX 2.9\tex\latex\minted\minted.sty"
("C:\Program Files\MiKTeX 2.9\tex\latex\graphics\keyval.sty")
("C:\Program Files\MiKTeX 2.9\tex\latex\oberdiek\kvoptions.sty"
("C:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\ltxcmds.sty")
("C:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\kvsetkeys.sty"
("C:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\infwarerr.sty")
("C:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\etexcmds.sty"
("C:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\ifluatex.sty"))))
("C:\Program Files\MiKTeX 2.9\tex\latex\fvextra\fvextra.sty"
("C:\Program Files\MiKTeX 2.9\tex\latex\base\ifthen.sty")
("C:\Program Files\MiKTeX 2.9\tex\latex\etoolbox\etoolbox.sty")
("C:\Program Files\MiKTeX 2.9\tex\latex\fancyvrb\fancyvrb.sty"
Style option: `fancyvrb' v3.2a <2019/01/15> (tvz))
("C:\Program Files\MiKTeX 2.9\tex\latex\upquote\upquote.sty")
("C:\Program Files\MiKTeX 2.9\tex\latex\lineno\lineno.sty"))
("C:\Program Files\MiKTeX 2.9\tex\latex\tools\calc.sty")
("C:\Program Files\MiKTeX 2.9\tex\latex\tools\shellesc.sty")
("C:\Program Files\MiKTeX 2.9\tex\latex\ifplatform\ifplatform.sty"
("C:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\pdftexcmds.sty"
("C:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\ifpdf.sty"))
("C:\Program Files\MiKTeX 2.9\tex\generic\oberdiek\catchfile.sty"))
("C:\Program Files\MiKTeX 2.9\tex\latex\xstring\xstring.sty"
("C:\Program Files\MiKTeX 2.9\tex\generic\xstring\xstring.tex"))
("C:\Program Files\MiKTeX 2.9\tex\latex\framed\framed.sty")
("C:\Program Files\MiKTeX 2.9\tex\latex\float\float.sty"))
("C:\Program Files\MiKTeX 2.9\tex\latex\xcolor\xcolor.sty"
("C:\Program Files\MiKTeX 2.9\tex\latex\graphics-cfg\color.cfg")
("C:\Program Files\MiKTeX 2.9\tex\latex\graphics-def\pdftex.def"))
E:\data>set  /p x=E:\Anaconda3\pkgs\pygments-2.3.1-py37_0\Scripts\pygmentize.exe 0<nul: 1>>untitled-2.aex 

E:\data>set  /p x= 0<nul: 1>>untitled-2.aex 

E:\data>set  /p x= 0<nul: 1>>untitled-2.aex 

No file untitled-2.aux.
("C:\Program Files\MiKTeX 2.9\tex\context\base\supp-pdf.mkii"
[Loading MPS to PDF converter (version 2006.09.02).]
)Unable to create process using 'E:\Anaconda3\pkgs\pygments-2.3.1-py37_0\python.exe E:\Anaconda3\pkgs\pygments-2.3.1-py37_0\Scripts\pygmentize-script.py -S default -f latex -P commandprefix=PYG '
 (_minted-untitled-2/default-pyg-prefix.pygstyle)Unable to create process using 'E:\Anaconda3\pkgs\pygments-2.3.1-py37_0\python.exe E:\Anaconda3\pkgs\pygments-2.3.1-py37_0\Scripts\pygmentize-script.py -S default -f latex -P commandprefix=PYGdefault '

(_minted-untitled-2/default.pygstyle)Unable to create process using 'E:\Anaconda3\pkgs\pygments-2.3.1-py37_0\python.exe E:\Anaconda3\pkgs\pygments-2.3.1-py37_0\Scripts\pygmentize-script.py -l python -f latex -P commandprefix=PYG -F tokenmerge -o _minted-untitled-2/A9E2CF9A87AD555C76527CE1FE6BA6800BAB9765B70F998031078A806C12B4A4.pygtex untitled-2.pyg'


! Package minted Error: Missing Pygments output; \inputminted was
probably given a file that does not exist--otherwise, you may need 
the outputdir package option, or may be using an incompatible build tool,
or may be using frozencache with a missing file.

See the minted package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.8 \end{minted}

? 

我还将 pygmentize.exe 添加到了 Path 环境变量中。我认为 pygmentize.exe 存在一些问题。

答案1

解决方案:要使 minted 正常工作,需要将 pygmentize.exe 添加到 Path 环境中。如果使用 conda 发行版,则可能有两个版本的 pygmentize.exe。

1)C:\Anaconda3\pkgs\pygments-2.3.1-py37_0\Scripts

2)C:\Anaconda3\Scripts

我将第一个目录添加到我的 Path 环境变量中,导致出现上述错误。删除第一个目录并添加第二个目录,问题解决,minted 运行正常。

每次更改环境变量时都需要重新启动 PC。

相关内容