Given the following LaTeX document (minimal.tex):

int main() {
    printf("hello, world");
    return 0;

I can build it with:

pdflatex -shell-escape  minimal.tex

But I would like to put the build files in another directory, so I use -output-directory=build, like:

pdflatex -shell-escape -output-directory=build minimal.tex

But this way I get:

[Loading MPS to PDF converter (version 2006.09.02).]
))) (./_minted-minimal/default-pyg-prefix.pygstyle)Error: cannot read infile: [Errno 2] No such file or directory: 'minimal.pyg'
system returned with code 256

! 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.

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

l.9 \end{minted}

The minimal.pyg actually is inside build directory, but it seems not to be found.

What can I do?

3 Answers 3


You need \usepackage[outputdir=build]{minted} to tell minted where the files went.


You can use currfile-abspath (a sub-package of currfile) to set minted's output directory automatically. Must be done before loading the minted package.

\ifthenelse{\equal{\theabsdir}{\thepwd}}% using ifthen package
%\ifdefstrequal{\theabsdir}{\thepwd}% using etoolbox package

Apparently doesn't work reliably with MiKTeX, see https://github.com/gpoore/minted/issues/268


I hope readers do not mind me expanding on David Carlisle's answer. I've seen the question asked in so many ways over the years. However, I do not see mention of the importance of project path when loading Minted package.

As an individual developer and writer I recently changed from TexStudio to try TeXiFy plugin for IntelliJ IDEA. I write in that context. I am not associated with those products.

I resolve Minted code listing exceptions by setting \usepackage[outputdir=../auxil]{minted}.

Minted.sty relies on Python Pygments package, and it's intermediate-stage auxilliary output file during compile. The process: load Latex packages, begin compiling, compile code fragments with Minted package into an intermediate compile file .pyg<...>, collect the file during PDF output, complete PDF output processing. If the intermediate .pyg<...> is not in the expected folder a PDF output exception will occur.

Compiling code with Latex minted.sty package conforms to a default root-based folder structure. Wherever the project sits in a folder hierarchy, that's the default. Default TeXiFy plugin does not--- it conforms to IntelliJ IDEA Ultimate's default structures (or your IDE of choice), which it is inevitably bound to comply with, as plugins do. Accordingly, when TeXiFy IDEA plugin compiles it seeks a .pyg<...> file in the wrong place. By default, here is the compiled structure for the simple MWE below...


Using Latex...

% Packages
% Document
        $x = 1;
            echo "x=1";
        } else {
            echo "x=" . $x;

It produces exception...

Error: cannot read infile: [Errno 2] No such file or directory: 'minted-mwe.pyg' Could Not Find P:\Writing-and-WritingSoftware\DevelopmentBooklets\VanElectrical\TexifyMintedTest\src_minted-minted-mwe\097AF5BD36CFF0D87D9991A6653D1FBAC2C2A1FBB8430C5273284E8D3B9D57CD.pygtex

That is correct. The .pyg<...> file should NOT be searched for under \TexifyMintedTest\ src folder, it is in \auxil folder.

By changing the outputdir folder using the correct file path when loading minted.sty, the compile process will seek the .pyg<...> file in the correct place...

minted-outputdir tex

HTH non-experts...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .