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.

Fails
\documentclass{article}
\usepackage{minted2}
\begin{document}
\begin{minted}{python}
def mean(xs):
    return sum(xs) / len(xs)
\end{minted}
\end{document}
Fixed
\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

Every example on this page was compiled with pdfLaTeX to check that it fails and is fixed as described. All LaTeX errors