Package minted Error: You must invoke LaTeX with the -shell-escape flag.
minted runs an external highlighter, which needs shell escape. Compile with -shell-escape where you may, or switch to the listings package.
Help centre › LaTeX errors › Commands and packages · Error: the build stops or the output is wrong
What the log says
! Package minted Error: You must invoke LaTeX with the -shell-escape flag.
See the minted package documentation for explanation.
Type H <return> for immediate help.Also printed as: Package minted Error: minted v3+ executable is not installed, is not added to PATH, or is not permitted with restricted shell escape
What it means
minted colors source code by running the Pygments highlighter, a program outside TeX. TeX may start outside programs only when shell escape is enabled, which is off by default because a document could otherwise run any command on the computer. Without it minted cannot highlight anything and stops.
Causes and fixes
Most common first. Each example is a complete document; the first fails with this message, the second is the same document fixed.
1. Shell escape is off, and cannot or should not be turned on
Use the listings package, which highlights code inside TeX: replace \begin{minted}{python} with \begin{lstlisting}[language=Python] and style it with \lstset. It needs no outside program and compiles everywhere, including on submission systems.
\documentclass{article}
\usepackage{minted2}
\begin{document}
\begin{minted}{python}
def mean(xs):
return sum(xs) / len(xs)
\end{minted}
\end{document}\documentclass{article}
\usepackage{listings}
\lstset{basicstyle=\ttfamily\small, keywordstyle=\bfseries}
\begin{document}
\begin{lstlisting}[language=Python]
def mean(xs):
return sum(xs) / len(xs)
\end{lstlisting}
\end{document}2. You compile on your own computer without the flag
Run pdflatex -shell-escape main.tex (or add -shell-escape to your editor's or latexmk's command), and install Pygments. Only do this for documents whose source you trust.
3. minted 3 cannot find its helper program
From version 3, minted runs its own program, latexminted, which some TeX distributions allow under restricted shell escape; the error then names the executable instead. Install it with your TeX distribution's package manager or compile with -shell-escape. \usepackage{minted2} keeps the old behavior.
In Manulyx
Shell escape is off in Manulyx, so minted and other packages that run outside programs do not work; use listings for code. See What Manulyx does not do.
Write in Manulyx for free · Journal templates
More in commands and packages
- Undefined control sequence.LaTeX met a command it does not know: usually a typo, or a command whose package is not loaded. The log's l. line ends with the culprit.
- Missing number, treated as zero.A command that needs a number or length (\vspace, \setcounter, a width) got a word or nothing. Give it a value such as 1em or 3.
- LaTeX Error: Command \<name> already defined.\newcommand or a package tried to define a name that already exists. Pick another name, use \renewcommand, or drop the clashing package.
- Illegal parameter number in definition of \<name>.A # in a definition does not refer to a declared argument: #1 without [1], #1 in an environment's end code, or a # in a URL. Fix the count or escape it.
- Use of \<name> doesn't match its definition.A command with a special argument syntax, such as \put(x,y) or a \def with delimiters, was called without that syntax. Follow its exact form.
- LaTeX Error: Environment <name> undefined\begin{…} names an environment no loaded package defines: load the package (amsmath for align), fix the spelling, or define it with \newtheorem.
Every example on this page was compiled with pdfLaTeX to check that it fails and is fixed as described. All LaTeX errors