0

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
/usr/bin/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}):

\documentclass[12pt]{article}
\special{papersize=3in,5in}
\usepackage[utf8]{inputenc}
\usepackage{amssymb,amsmath}
\usepackage{minted}
\pagestyle{empty}
\setlength{\parindent}{0in}
\begin{document}
\tiny

Successful test on command line:

test.tex

\documentclass[12pt]{article}
\special{papersize=3in,5in}
\usepackage[utf8]{inputenc}
\usepackage{amssymb,amsmath}
\usepackage{minted}
\pagestyle{empty}
\setlength{\parindent}{0in}
\begin{document}
\begin{minted}{cpp}

    #include
    using namespace std;
    int main()
    {
        return 0;
    }

\end{minted}
\end{document}

Shell command:

~ % latex -shell-escape test.tex

Unsuccessful test in Anki:

[latex]
\begin{minted}{cpp}

#include
using namespace std;
int main()
{
    return 0;
}

\end{minted}
[/latex]

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
(./tmp.tex
LaTeX2e <2015/01/01>
Babel <3.9l> and hyphenation patterns for 21 languages loaded.
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/base/size12.clo))
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/base/inputenc.sty
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/base/utf8.def
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/base/t1enc.dfu)
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/base/ot1enc.dfu)
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/base/omsenc.dfu)))
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/amsfonts/amssymb.sty
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/amsfonts/amsfonts.sty))
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/amsmath/amsopn.sty))
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/minted/minted.sty
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/oberdiek/kvoptions.sty
(/usr/local/texlive/2015basic/texmf-   dist/tex/generic/oberdiek/ltxcmds.sty)
(/usr/local/texlive/2015basic/texmf-  dist/tex/generic/oberdiek/kvsetkeys.sty
(/usr/local/texlive/2015basic/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(/usr/local/texlive/2015basic/texmf-dist/tex/generic/oberdiek/etexcmds.sty
(/usr/local/texlive/2015basic/texmf-dist/tex/generic/oberdiek/ifluatex.sty))))
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/fancyvrb/fancyvrb.sty
Style option: `fancyvrb' v2.7a, with DG/SPQR fixes, and firstline=lastline fix 
<2008/02/07> (tvz))
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/float/float.sty)
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/base/ifthen.sty)
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/tools/calc.sty)
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/ifplatform/ifplatform.sty
(/usr/local/texlive/2015basic/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty
(/usr/local/texlive/2015basic/texmf-dist/tex/generic/oberdiek/ifpdf.sty))
(/usr/local/texlive/2015basic/texmf-dist/tex/generic/oberdiek/catchfile.sty)
(./tmp.w18))
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/etoolbox/etoolbox.sty)
(/usr/local/texlive/2015basic/texmf-dist/tex/generic/xstring/xstring.sty
(/usr/local/texlive/2015basic/texmf-dist/tex/generic/xstring/xstring.tex))
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/lineno/lineno.sty))
(./_minted-tmp/default.pygstyle)/usr/local/bin/pygmentize
(./tmp.aux)
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/xcolor/xcolor.sty
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/latexconfig/color.cfg)
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/graphics/dvips.def))
(./_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). – stefanfrede 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. – stefanfrede 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
2

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:

/Library/Python/2.7/site-packages/PyInstaller/building/api.py
/Library/Python/2.7/site-packages/PyInstaller/building/osx.py
/Library/Python/2.7/site-packages/PyInstaller/building/utils.py
/Library/Python/2.7/site-packages/PyInstaller/lib/macholib/util.py

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!

Stephan

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.