[Tex/LaTex] Cannot get ‘pygmentize’ to work correctly on mac

mintedpygments

I am using TeXworks on Mac osX 10.7.5 and I'm trying to compile some python code within my tex file but with limited success.

My tex file looks like:

\documentclass[12pt,A4]{article}
\usepackage{minted}
\begin{document}

\begin{minted}{python}

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

\end{minted}

\end{document}

When I run the tex file with the command:

pdflatex --shell-escape path.tex

I get the following error:

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

The strange thing is, when I run the command, then type "quit". The PDF is produced as expected but how can I get it to produce the file without the error?

I have installed the latest version of minted and pygments. The terminal finds pygmentize:

ucbthsa-2:bin ucbthsa$ which pygmentize
/Library/Frameworks/Python.framework/Versions/Current/bin/pygmentize

I have had a look at another similar question but it has not helped

Best Answer

Recently I had the same problem. The issue was that TeXworks has different PATH environment from your terminal. My solution was to create a symbolic link to pygmentize from /Library/Frameworks/Python.framework/Versions/3.5/bin/pygmentize to /usr/local/bin.