4

Installed MacTex2023 on a new Mac and all is well except for a nagging issue with "pygmentize" that I've already installed. I cannot find how to adjust system to recognise the installed "pygmentize" that exists in my "/Users//Library/Python/3.9/bin" folder.

I have upgraded to Python 3.11 and used pip3 to confirm that Pygments 2.14.0 is installed.

I've already checked those SE pages that discuss Pygmentize issues, e.g. at Pygmentize not working properly with minted package in TexShop on OS X

Additional specs via 'pip3 list': Package Version


  1. altgraph 0.17.2
  2. future 0.18.2
  3. macholib 1.15.2
  4. pip 23.0.1
  5. Pygments 2.14.0
  6. setuptools 67.6.0
  7. six 1.15.0
  8. wheel 0.40.0

Note: When I run the following minimal LaTeX package, I see the same error:

\documentclass{article}
\usepackage{minted}
\begin{document}
    \begin{minted}{c}
    int main() {
    printf("hello, world");
    return 0;
    }
    \end{minted}
\end{document}

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

Note 2: I Typeset to LaTeX using TexShop.

41
  • Did you compile with the -shell-escape flag? That is necessary for the package to work.
    – Amarakon
    Commented Mar 26, 2023 at 4:39
  • @Amarakon - Thanks for the question. In the TeXShop preferences > Engine > pdfTeX > Latex field I have the following command: pdflatex --file-line-error --synctex=1 --shell-escape, which I assume turns ON the -shell-escape flag ... n'est pas? Is there something else I need to do? Commented Mar 26, 2023 at 4:47
  • Yep, that should do it.
    – Amarakon
    Commented Mar 26, 2023 at 5:17
  • @Amarakon - Thank you! The whole -shell-escape flag issue took me a bit to research ... now I need to research a bit more to address the issue with pygmentize .... unless someone else has had the same issue, and a solution. Thanks for your comment! Commented Mar 26, 2023 at 5:47
  • I ran into the same problem using LuaLatex. The strange thing was the work around I discovered in trial-and-error: first compile with PDFLatex (be aware of the use of fontspec / fontenc differences between the two), which generated the required minted output. Then compile again with LuaLatex to get the final PDF. I am using TeXStudio/MikTeX (fully upgraded). Checking the pathways in both compilations revealed a strange issue: in LuaLatex the whole pathway was replaced with only one line pointing towards the MikTeX installation....
    – alchemist
    Commented Mar 26, 2023 at 8:29

3 Answers 3

3

Eureka (I wish this would have been easier, e.g. from this TeXShop page).

Caveat: I tested this with a TeXShop 3.89 which is nowadays an old version.

To let TeXShop use --shell-escape for only one specific document you can:

  • instead of hitting "Compile" (or whatever is English word), go to Macros>Claus Gerhardt Macros and then choose pdflatexc. It launches the compilation using --shell-escape flag. (I discovered that by digging into ~/Library/TeXShop/bin/).

I tried many % !TeX variants such as % !TEX TS-program="pdflatex --shell-escape" but this fails, and perhaps there is a parameter TS-program-options but I stopped my search after above workaround.

But first you also need that TeXShop finds pygmentize.

An answer is given at https://tex.stackexchange.com/a/281188/293669 which worked for me.

On my installation (which is a direct TeXLive install) I do not need the sudo so simply

ln -s "$(which pygmentize)" /Library/TeX/texbin/pygmentize

in Terminal.

Perhaps execute first which pygmentize and pygmentize -V to confirm it is correctly installed, prior to symlink it to the directory where TeXShop finds TeX binaries. The above should apply on MacTeX based installations. For direct TeXLive installations on (old) Macs, replace /Library/TeX/texbin/pygmentize by something such as /usr/local/texlive/2023/bin/x86_64-darwinlegacy/pygmentize.

2
  • Sadly, the Macros>Claus Gerhardt Macros>pdflatexc method wll not display nor update the console showing output to terminal from the pdflatex run.
    – user691586
    Commented Mar 26, 2023 at 14:52
  • Understood ... Thank you for this option, and for ALL your research!! Commented Apr 1, 2023 at 18:20
2

The pygmentize issue can be addressed by installing pygments with pip2.

sudo pip2 install pygments

This method works on my cases.

1

I have encountered the same issue. I realised that pdflatex relies on Unix/Linux command line utility called which to confirm, that pygmentize is available. I didn't have it installed on my system and LaTeX compilation aborted with the same error you mentioned above:

You must have `pygmentize' installed to use this package.

In my case installing which resolved the problem. Be attentive and do not repeat my mistake.

You must log in to answer this question.

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