PyLatex basic script won't run because script interpreter could not be found
You can change the compiler to pdflatex instead of latexmk which will work if you have installed miktex and pdflatex . latexmk is compiler by default.
doc.generate_pdf(clean_tex=False,compiler='pdfLaTeX')
If anyone stumbles upon this it turns out that for PyLatex to work you also have to have Perl installed. Once I downloaded Perl from here it worked. Make sure Perl is in the PATH.
I am using Python 2.7.14 :: Anaconda, Inc. and I faced the same issue when I first tried to execute the PyLaTeX's example available at https://jeltef.github.io/PyLaTeX/latest/examples/basic.html.
1) When I executed the copied code before installation of MikTeX
(pylatex) G:\RishikeshAgrawani\ProjectsWin7\Python3\PyLaTeX\pylatex\01_basic>python 01
Traceback (most recent call last):
File "01_basic.py", line 24, in <module>
doc.generate_pdf(clean_tex=False)
File "C:\Anaconda2.5.0.1\lib\site-packages\pylatex\document.py", line 317, in genera
u'or make sure you have latexmk or pdfLaTex installed.'
pylatex.errors.CompilerError: No LaTex compiler was found
Either specify a LaTex compiler or make sure you have latexmk or pdfLaTex installed.
2) After installation of MikTeX
You can see above output, it is looking for LaTex compiler
that we can install by installing MikTeX.
Also read Using latexmk with MikTeX.
You can download MikTeX at https://miktex.org/download.
(C:\Anaconda2.5.0.1) G:\RishikeshAgrawani\ProjectsWin7\Python3\PyLaTeX\pylatex\01_basic>python 01_basic.py
latexmk: The script engine could not be found.
latexmk: Data: scriptEngine="perl.exe"
Traceback (most recent call last):
File "01_basic.py", line 24, in <module>
doc.generate_pdf(clean_tex=False)
File "C:\Anaconda2.5.0.1\lib\site-packages\pylatex\document.py", line 269, in generate_pdf
stderr=subprocess.STDOUT)
File "C:\Anaconda2.5.0.1\lib\subprocess.py", line 219, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '[u'latexmk', u'--pdf', u'--interaction=nonstopmode', u'basic.tex']' returned non-zero exit
status 1
3) After installation of STARWBERRY PERL
You can see above ouptput, it is looking for perl.exe
.
So I downloaded Strawberry perl from http://strawberryperl.com/ and installed it.
Now I successfully ran the code and got the PDF.
(C:\Anaconda2.5.0.1) G:\RishikeshAgrawani\ProjectsWin7\Python3\PyLaTeX\pylatex\01_basic>python 01_basic.py
(C:\Anaconda2.5.0.1) G:\RishikeshAgrawani\ProjectsWin7\Python3\PyLaTeX\pylatex\01_basic>
That's it.