[Tex/LaTex] Pygmentize not working properly with minted package in TexShop on OS X

mactexmintedpygmentstexshop

I am using TexShop on mac OS X 10.11.1 and I'm trying to output some Python code inside my LaTeX document.

Here is an example of a document I would want to produce :

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[francais]{babel}
\usepackage{minted}
\begin{document}

\begin{minted}{python}

    def __init__(self, x, y): 
        self.x=x
        self.y=y

\end{minted}

\end{document}

My LaTeX compile command is pdflatex --file-line-error --synctex=1 --shell-escape --interaction=nonstopmode.

When the command is run directly from the terminal, it works fine. But whenever I try to compile the document from TexShop, I get the following error :

 sh: /Library/TeX/texbin/pygmentize: cannot execute binary file

I also got this error previously :

sh: /Library/TeX/texbin/pygmentize: access denied

I have Python installed, minted package up to date, pygmentize installed and located at ~/anaconda/bin/pygmentize, with symbolic links the following directories : /usr/local/bin/, /usr/local/texlive/2015/bin/x86_64-darwin/ and /Library/Tex/texbin/.

Now, what can I do to get minted to work

By the way, if I run this test file

\catcode`:=\active
\def:{\par}

\parindent0pt\tt

\input|"echo $PATH"

\bigskip

Is there pygmentize?

\input|"which pygmentize"

\bye

I get

/Users/philippe/anaconda/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/Library/TeX/texbin
Is there pygmentize?
/Users/philippe/anaconda/bin/pygmentize

Best Answer

I had the same problem and it took me a while until I realized it was TeXShop causing all the trouble. Like you already mentioned, you need a reference to pygmentize within /Library/TeX/texbin, but it's sufficient to create a symlink instead of a copy:

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