5

I'm try to use the minted package in latex to display code in latex document. From Texstudio, I get an error message you must have pygmentize installed to use this package .

If I type pip3 install pygments I get Requirement already satisfied: pygments in /usr/local/lib/python3.7/site-packages (2.3.1) which means that pip3 has installed on the machine.

So after typing pip3 show Pygments I get the path where that package is installed namely: /usr/local/lib/python3.7/site-packages. Moreover, when I launch python from the Terminal and type import pygments no error message is displayed. That means that it is correctly installed but that the latex editor cannot find it.

What am I doing wrong?

Edit as pointed in the answers below

I get as the first message:

Package minted Error: You must invoke LaTeX with the -shell-escape flag. \begin

only then I get:

Package minted Error: You must have `pygmentize' installed to use this package. \begin{document}
Package minted Error: Missing Pygments output; \inputminted wasor may be using frozencache with a missing file. \end{minted}^^M
Package minted Error: Missing Pygments output; \inputminted wasor may be using frozencache with a missing file. \end{minted}^^M
Package minted Error: Missing Pygments output; \inputminted wasor may be using frozencache with a missing file. \end{minted}
shell escape is disabled, so I can only detect \ifwindows.

Here is a piece of code:

\documentclass[a4paper, 12pt]{book}
\usepackage{minted}
\begin{document}
\chapter{Introduction}
\begin{minted}{python}
print("hello world")
\end{minted}
\end{document}

Edit 2

As pointed out in another answer, the problem seems to be in the configuration option. So after going in "Textstudio > Preferences > Build" I clicked on the Add button and entered pdflatex -shell-escape in the left cell and pdflatex -synctex=1 -interaction=nonstopmode --shell-escape %.tex in the right cell as shown below:

add command

I do get a new command in the User Menu:

enter image description here

I then quit this menu, but the problem persisted.

What am I still missing

Here is the list of the log file:

log file

Here is the printed log file:

This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdflatex 2018.9.16)  23 APR 2019 20:44
entering extended mode
 restricted \write18 enabled.
 %&-line parsing enabled.
**python_latex.tex
(./python_latex.tex
LaTeX2e <2018-04-01> patch level 2
Babel <3.18> and hyphenation patterns for 84 language(s) loaded.
(/usr/local/texlive/2018/texmf-dist/tex/latex/base/book.cls
Document Class: book 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2018/texmf-dist/tex/latex/base/bk12.clo
File: bk12.clo 2014/09/29 v1.4h Standard LaTeX file (size option)
)
\c@part=\count80
\c@chapter=\count81
\c@section=\count82
\c@subsection=\count83
\c@subsubsection=\count84
\c@paragraph=\count85
\c@subparagraph=\count86
\c@figure=\count87
\c@table=\count88
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
)
(/usr/local/texlive/2018/texmf-dist/tex/latex/minted/minted.sty
Package: minted 2017/07/19 v2.5 Yet another Pygments shim for LaTeX

(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics/keyval.sty Package: keyval 2014/10/28 v1.15 key=value parser (DPC) \KV@toks@=\toks14 ) (/usr/local/texlive/2018/texmf-dist/tex/latex/oberdiek/kvoptions.sty Package: kvoptions 2016/05/16 v3.12 Key value format for package options (HO)

(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/ltxcmds.sty Package: ltxcmds 2016/05/16 v1.23 LaTeX kernel commands for general use (HO) ) (/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty Package: kvsetkeys 2016/05/16 v1.17 Key value parser (HO)

(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/infwarerr.sty Package: infwarerr 2016/05/16 v1.4 Providing info/warning/error messages (HO) ) (/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/etexcmds.sty Package: etexcmds 2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO)

(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/ifluatex.sty Package: ifluatex 2016/05/16 v1.4 Provides the ifluatex switch (HO) Package ifluatex Info: LuaTeX not detected. ) Package etexcmds Info: Could not find \expanded. (etexcmds) That can mean that you are not using pdfTeX 1.50 or (etexcmds) that some package has redefined \expanded. (etexcmds) In the latter case, load this package earlier. ))) (/usr/local/texlive/2018/texmf-dist/tex/latex/fvextra/fvextra.sty Package: fvextra 2017/07/08 v1.3.1 fvextra - extensions and patches for fancyvr b

(/usr/local/texlive/2018/texmf-dist/tex/latex/base/ifthen.sty Package: ifthen 2014/09/29 v1.1c Standard LaTeX ifthen package (DPC) ) (/usr/local/texlive/2018/texmf-dist/tex/latex/etoolbox/etoolbox.sty Package: etoolbox 2018/02/11 v2.5e e-TeX tools for LaTeX (JAW) \etb@tempcnta=\count89 ) (/usr/local/texlive/2018/texmf-dist/tex/latex/fancyvrb/fancyvrb.sty Package: fancyvrb 2008/02/07

Style option: `fancyvrb' v2.7a, with DG/SPQR fixes, and firstline=lastline fix <2008/02/07> (tvz) \FV@CodeLineNo=\count90 \FV@InFile=\read1 \FV@TabBox=\box26 \c@FancyVerbLine=\count91 \FV@StepNumber=\count92 \FV@OutFile=\write3 ) (/usr/local/texlive/2018/texmf-dist/tex/latex/upquote/upquote.sty Package: upquote 2012/04/19 v1.3 upright-quote and grave-accent glyphs in verba tim ) (/usr/local/texlive/2018/texmf-dist/tex/latex/lineno/lineno.sty Package: lineno 2005/11/02 line numbers on paragraphs v4.41 \linenopenalty=\count93 \output=\toks15 \linenoprevgraf=\count94 \linenumbersep=\dimen103 \linenumberwidth=\dimen104 \c@linenumber=\count95 \c@pagewiselinenumber=\count96 \c@LN@truepage=\count97 \c@internallinenumber=\count98 \c@internallinenumbers=\count99 \quotelinenumbersep=\dimen105 \bframerule=\dimen106 \bframesep=\dimen107 \bframebox=\box27 LaTeX Info: Redefining \ on input line 3056. ) \c@FV@TrueTabGroupLevel=\count100 \c@FV@TrueTabCounter=\count101 \FV@TabBox@Group=\box28 \FV@TmpLength=\skip43 \c@FV@HighlightLinesStart=\count102 \c@FV@HighlightLinesStop=\count103 \FV@LoopCount=\count104 \FV@NCharsBox=\box29 \FV@BreakIndent=\dimen108 \FV@BreakIndentNChars=\count105 \FV@BreakSymbolSepLeft=\dimen109 \FV@BreakSymbolSepLeftNChars=\count106 \FV@BreakSymbolSepRight=\dimen110 \FV@BreakSymbolSepRightNChars=\count107 \FV@BreakSymbolIndentLeft=\dimen111 \FV@BreakSymbolIndentLeftNChars=\count108 \FV@BreakSymbolIndentRight=\dimen112 \FV@BreakSymbolIndentRightNChars=\count109 \c@FancyVerbLineBreakLast=\count110 \FV@LineBox=\box30 \FV@LineIndentBox=\box31 ) (/usr/local/texlive/2018/texmf-dist/tex/latex/tools/calc.sty Package: calc 2017/05/25 v4.3 Infix arithmetic (KKT,FJ) \calc@Acount=\count111 \calc@Bcount=\count112 \calc@Adimen=\dimen113 \calc@Bdimen=\dimen114 \calc@Askip=\skip44 \calc@Bskip=\skip45 LaTeX Info: Redefining \setlength on input line 80. LaTeX Info: Redefining \addtolength on input line 81. \calc@Ccount=\count113 \calc@Cskip=\skip46 ) (/usr/local/texlive/2018/texmf-dist/tex/latex/tools/shellesc.sty Package: shellesc 2016/06/07 v0.02a unified shell escape interface for LaTeX Package shellesc Info: Restricted shell escape enabled on input line 69. ) (/usr/local/texlive/2018/texmf-dist/tex/latex/ifplatform/ifplatform.sty Package: ifplatform 2017/10/13 v0.4a Testing for the operating system

(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty Package: pdftexcmds 2018/01/30 v0.27 Utility functions of pdfTeX for LuaTeX (HO )

(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/ifpdf.sty Package: ifpdf 2017/03/15 v3.2 Provides the ifpdf switch ) Package pdftexcmds Info: LuaTeX not detected. Package pdftexcmds Info: \pdf@primitive is available. Package pdftexcmds Info: \pdf@ifprimitive is available. Package pdftexcmds Info: \pdfdraftmode found. ) (/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/catchfile.sty Package: catchfile 2016/05/16 v1.7 Catch the contents of a file (HO) )

Package ifplatform Warning: shell escape is disabled, so I can only detect \ifwindows.

) (/usr/local/texlive/2018/texmf-dist/tex/generic/xstring/xstring.sty (/usr/local/texlive/2018/texmf-dist/tex/generic/xstring/xstring.tex @xs@message=\write4 \integerpart=\count114 \decimalpart=\count115 ) Package: xstring 2013/10/13 v1.7c String manipulations (C Tellechea) ) (/usr/local/texlive/2018/texmf-dist/tex/latex/framed/framed.sty Package: framed 2011/10/22 v 0.96: framed or shaded text with page breaks \OuterFrameSep=\skip47 \fb@frw=\dimen115 \fb@frh=\dimen116 \FrameRule=\dimen117 \FrameSep=\dimen118 ) (/usr/local/texlive/2018/texmf-dist/tex/latex/float/float.sty Package: float 2001/11/08 v1.3d Float enhancements (AL) \c@float@type=\count116 \float@exts=\toks16 \float@box=\box32 @float@everytoks=\toks17 @floatcapt=\box33 ) \minted@appexistsfile=\read2 \minted@bgbox=\box34 \minted@code=\write5 \c@minted@FancyVerbLineTemp=\count117 \c@minted@pygmentizecounter=\count118 @float@every@listing=\toks18 \c@listing=\count119 ) runsystem(mkdir -p _minted-python_latex)...disabled (restricted).

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

l.3 \begin {document} Pass the -shell-escape flag to LaTeX. Refer to the minted.sty documentation for more information.

(/usr/local/texlive/2018/texmf-dist/tex/latex/xcolor/xcolor.sty Package: xcolor 2016/05/11 v2.12 LaTeX color extensions (UK)

(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics-cfg/color.cfg File: color.cfg 2016/01/02 v1.6 sample color configuration ) Package xcolor Info: Driver file: pdftex.def on input line 225.

(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics-def/pdftex.def File: pdftex.def 2018/01/08 v1.0l Graphics/color driver for pdftex ) Package xcolor Info: Model cmy' substituted bycmy0' on input line 1348. Package xcolor Info: Model hsb' substituted byrgb' on input line 1352. Package xcolor Info: Model RGB' extended on input line 1364. Package xcolor Info: ModelHTML' substituted by rgb' on input line 1366. Package xcolor Info: ModelHsb' substituted by hsb' on input line 1367. Package xcolor Info: ModeltHsb' substituted by hsb' on input line 1368. Package xcolor Info: ModelHSB' substituted by hsb' on input line 1369. Package xcolor Info: ModelGray' substituted by gray' on input line 1370. Package xcolor Info: Modelwave' substituted by `hsb' on input line 1371. ) runsystem(which pygmentize && touch python_latex.aex)...disabled (restricted).

! Package minted Error: You must have `pygmentize' installed to use this packag e.

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

l.3 \begin{document}

Refer to the installation instructions in the minted documentation for more inf ormation.

(./python_latex.aux) \openout1 = `python_latex.aux'.

LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 3. LaTeX Font Info: ... okay on input line 3. LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 3. LaTeX Font Info: ... okay on input line 3. LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 3. LaTeX Font Info: ... okay on input line 3. LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 3. LaTeX Font Info: ... okay on input line 3. LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 3. LaTeX Font Info: ... okay on input line 3. LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 3. LaTeX Font Info: ... okay on input line 3.

(/usr/local/texlive/2018/texmf-dist/tex/context/base/mkii/supp-pdf.mkii [Loading MPS to PDF converter (version 2006.09.02).] \scratchcounter=\count120 \scratchdimen=\dimen119 \scratchbox=\box35 \nofMPsegments=\count121 \nofMParguments=\count122 \everyMPshowfont=\toks19 \MPscratchCnt=\count123 \MPscratchDim=\dimen120 \MPnumerator=\count124 \makeMPintoPDFobject=\count125 \everyMPtoPDFconversion=\toks20 ) Chapter 1. \openout3 = `python_latex.pyg'.

runsystem(pygmentize -S default -f latex -P commandprefix=PYG > minted-python latex/default-pyg-prefix.pygstyle)...disabled (restricted).

! 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.7 \end{minted}^^M

This could be caused by using -output-directory or -aux-directory without setting minted's outputdir, or by using a build tool that changes paths in ways minted cannot detect, or using frozencache with a missing file.

runsystem(pygmentize -S default -f latex -P commandprefix=PYGdefault > _minted- python_latex/default.pygstyle)...disabled (restricted).

! 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.7 \end{minted}^^M

This could be caused by using -output-directory or -aux-directory without setting minted's outputdir, or by using a build tool that changes paths in ways minted cannot detect, or using frozencache with a missing file.

runsystem(pygmentize -l python -f latex -P commandprefix=PYG -F tokenmerge -o _ minted-python_latex/72214DB4E1E543018D1BAFE86EA3B4440B40C301701A64D52CDA79C72DA 628CC.pygtex python_latex.pyg)...disabled (restricted).

! 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.7 \end{minted}

This could be caused by using -output-directory or -aux-directory without setting minted's outputdir, or by using a build tool that changes paths in ways minted cannot detect, or using frozencache with a missing file.

[1

{/usr/local/texlive/2018/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] (./python_latex.aux) runsystem(rm python_latex.pyg)...disabled (restricted).

) Here is how much of TeX's memory you used: 4355 strings out of 492649 78111 string characters out of 6129622 188991 words of memory out of 5000000 8209 multiletter control sequences out of 15000+600000 4544 words of font info for 17 fonts, out of 8000000 for 9000 1141 hyphenation exceptions out of 8191 37i,5n,35p,843b,142s stack positions out of 5000i,500n,10000p,200000b,80000s </usr/local/texlive/2018/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx12.pfb ></usr/local/texlive/2018/texmf-dist/fonts/type1/public/amsfonts/cm/cmr12.pfb> Output written on python_latex.pdf (1 page, 17712 bytes). PDF statistics: 16 PDF objects out of 1000 (max. 8388607) 10 compressed objects within 1 object stream 0 named destinations out of 1000 (max. 500000) 1 words of extra memory for PDF output out of 10000 (max. 10000000)

ANSWER As pointed out in the post from the linked question just insert the following line in the document: % !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape]

ecjb
  • 883
  • Are you using --shell-escape when you typeset your document? – Herb Schulz Apr 22 '19 at 19:31
  • thank you for your comment @HerbSchulz. Sorry, but I don't know what it is. What can I do to be able to give you an answer? – ecjb Apr 22 '19 at 19:47
  • The shell command you are looking for is pygmentize as shown so at a command line prompt you should be able to run pygmentize -V and get reply similar to Pygments version 2.3.1, (c) 2006-2017 by Georg Brandl. For TeX to be able to run similar commands and get results it needs to escape to the shell so its commands need to become pdfLaTeX --shell-escape..... other parts of command line tex file –  Apr 23 '19 at 16:32
  • thank you for your comment @KJO. I indeed get Pygments version 2.3.1, (c) 2006-2017 by Georg Brandl when typing pygmentize -V from the shell. Then my question. How do I exactly make Tex to run similar commands? – ecjb Apr 23 '19 at 16:43
  • that's where changing tex studio command line to include the external calls is a potential problem usually you can go to the folder with tex and commandline run pdfLaTeX -shell-escape main.tex to check all is well then in editor change existing command to include the same extra command argument. –  Apr 23 '19 at 16:44
  • show the log file from your test file, impossible to debug otherwise. – David Carlisle Apr 23 '19 at 18:32
  • I took a screenshot from the logfile – ecjb Apr 23 '19 at 18:34
  • I don't use texstudio but looking at the image you show I would guess you have defined a "pdflatex-shell-escape" command but your document is still using the default "pdflatex" command, but there are texstudio specific instructions in the linked duplicate – David Carlisle Apr 23 '19 at 18:35
  • it is always better to post log files as text screen shots are hard to read and impossible to search – David Carlisle Apr 23 '19 at 18:36
  • Thank you very much @DavidCarlisle. I will continue looking in that duplicate question. The log file displayed are very long. that's why I took a picture – ecjb Apr 23 '19 at 18:37
  • that is not the log file that is just a summary but read it! the first line confirms you have still not specified shell escape. – David Carlisle Apr 23 '19 at 18:37
  • in tex studio the default build and view is still set to old values so use just the new user cummand and then a view to see the pygment results –  Apr 23 '19 at 18:40

1 Answers1

5

is

! Package minted Error: You must have 'pygmentize' installed to use this package.

The first error message you get or before that do you get

! Package minted Error: You must invoke LaTeX with the -shell-escape flag.

Check the log file from the latex run which should also not say on line 3

restricted \write18 enabled.

it should say

\write18 enabled.

If the log is saying restricted write18, then use the -shell-escape option to pdflatex.

David Carlisle
  • 757,742
  • Thank you @DavidCarlisle. I edited the question following your advices. However I don't get neither 'restricted \write18 enabled' nor '\write18 enabled'. Do you have any other ideas? – ecjb Apr 23 '19 at 15:46
  • @ecjb You do get the warning telling you that you have not used -shell-escape as guessed in the very first comment under your question. (You should really always (only) show the first error reported by TeX) So that is the answer use pdflatex -shell-escape file not pdlfatex file (the minted manual is very clear that you need this) – David Carlisle Apr 23 '19 at 17:20
  • 1
    @ecjb your comment above is wrong, you have now posted the log file and line 3 says restricted \write18 enabled. so you are still not using shell-escape. Really you do not have to get your editor to type the command for you all you have to do is type pdflatex --shell-escape file on the terminal. If you find using an editor menu easier then fine but if it is making things difficult don't do it (I never run tex from a menu) – David Carlisle Apr 23 '19 at 19:17
  • it worked from the Terminal although it still doesn't work from TeXstudio. May I ask you which system you use to efficiently go back and forth from writing the source .tex file and checking the .pdf output? – ecjb Apr 23 '19 at 20:20
  • @ecjb I use emacs as my editor and usually xpdf as the pdf viewer, I could launch tex from the editor but usually I just run it directly on the terminal. – David Carlisle Apr 23 '19 at 20:22