On the command line everything works fine but in in Anki I get a python error.

My computer:

MacBook Air (13-inch, Mid 2012)
Processor 2 GHz Intel Core i7
Memory 8 GB 1600 MHz DDR3

My operating system:

OS X El Capitan
Version 10.11 (15A284)

My python library

~ % which python

My python version:

~ % python -V
Python 2.7.10

This is my Edit_LaTeX_build_process.py file (Note: -shell-escape):

newLaTeX = \
    ["/Library/TeX/texbin/latex", "-shell-escape", "-interaction=nonstopmode", "tmp.tex"],
    ["/Library/TeX/texbin/dvipng", "-D", "200", "-T", "tight", "tmp.dvi", "-o", "tmp.png"]

# make the changes
import anki.latex
anki.latex.latexCmds = newLaTeX

These are my Card options (Note: \usepackage{minted}):


Successful test on command line:



    using namespace std;
    int main()
        return 0;


Shell command:

~ % latex -shell-escape test.tex

Unsuccessful test in Anki:


using namespace std;
int main()
    return 0;


Error output:

Error executing /Library/TeX/texbin/latex.
Generated file:   /var/folders/_q/53_csl094rqfn9rr18bn3bpw0000gn/T/anki_temp/tmp.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015)  (preloaded format=latex)
\write18 enabled.
entering extended mode
LaTeX2e <2015/01/01>
Babel <3.9l> and hyphenation patterns for 21 languages loaded.
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2015basic/texmf-   dist/tex/generic/oberdiek/ltxcmds.sty)
(/usr/local/texlive/2015basic/texmf-  dist/tex/generic/oberdiek/kvsetkeys.sty
Style option: `fancyvrb' v2.7a, with DG/SPQR fixes, and firstline=lastline fix 
<2008/02/07> (tvz))
(./_minted-tmp/default-pyg-prefix.pygstyle)Traceback (most recent call   last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site- packages/py2app/apptemplate/lib/site.py", line 22, in <module>
zipimport.ZipImportError: can't decompress data; zlib not available

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

(./tmp.aux) )
(see the transcript file for additional information)
No pages of output.
Transcript written on tmp.log.

Any help getting this to work is very much appreciated because after trying to get this to work for over a day now I ran out of ideas.

  • This looks like an issue with the Python installation. According to the end of the log, Python can't find zlib.
    – G. Poore
    Oct 13 '15 at 11:30
  • Yes, it seems so but the odd thing is that on the command line everything works fine (no python error whatsoever).
    – user89697
    Oct 13 '15 at 14:22
  • Have you tried running pygmentize -V on the command line (to get Pygments version)? If that gives an error, it might help. Also, have you tried importing zlib after starting Python on the command line?
    – G. Poore
    Oct 13 '15 at 14:27
  • I just ran pygmentize -V and got no error and also starting python on the command line and importing zlib went fine. Somehow I get the feeling that it is an Anki related problem.
    – user89697
    Oct 15 '15 at 8:33
  • 1
    It looks like Anki is being bundled as a standalone application with py2app, and that is breaking. Possibly related/relevant.
    – G. Poore
    Oct 15 '15 at 11:56

I believe that the problem is that pygmentize which is called by the minted package is a python script. When called from inside Anki.app, pygmentize uses the python environment inside of Anki, which is not a complete python distribution.

Anyhow, I solved this by making pygmentize a standalone executable using PyInstaller:

$ sudo pip install pyinstaller

Unfortunately the current version of pyinstaller has a problem on El Capitan (issue tracker) which is however relatively easy to fix. Use a text editor to replace all instances of shutil.copy2 to shutil.copy in the following files:


Now you can build the standalone pygmentize executable and move it in place:

$ cd ~
$ pyinstaller --onefile /usr/local/bin/pygmentize
$ sudo mv /usr/local/bin/pygmentize /usr/local/bin/pygmentize~
$ sudo cp dist/pygmentize /usr/local/bin/pygmentize

This worked for me. I hope this helps!



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy