问题
I am trying to run the exact code from here to get an example of pylatex working.
In the directory that I am working in, I have copied and pasted from the link:
from pylatex import Document, Section, Subsection, Command
from pylatex.utils import italic, NoEscape
import pdflatex
def fill_document(doc):
    """Add a section, a subsection and some text to the document.
    :param doc: the document
    :type doc: :class:`pylatex.document.Document` instance
    """
    with doc.create(Section('A section')):
        doc.append('Some regular text and some ')
        doc.append(italic('italic text. '))
        with doc.create(Subsection('A subsection')):
            doc.append('Also some crazy characters: $&#{}')
if __name__ == '__main__':
    # Basic document
    doc = Document('basic')
    fill_document(doc)
    doc.generate_pdf(clean_tex=False,compiler='pdflatex')
    doc.generate_tex()
    # Document with `\maketitle` command activated
    doc = Document()
    doc.preamble.append(Command('title', 'Awesome Title'))
    doc.preamble.append(Command('author', 'Anonymous author'))
    doc.preamble.append(Command('date', NoEscape(r'\today')))
    doc.append(NoEscape(r'\maketitle'))
    fill_document(doc)
    doc.generate_pdf('basic_maketitle', clean_tex=False)
    # Add stuff to the document
    with doc.create(Section('A second section')):
        doc.append('Some text.')
    doc.generate_pdf('basic_maketitle2', clean_tex=False)
    tex = doc.dumps()  # The document as string in LaTeX syntax
I consistently get the error:
Traceback (most recent call last):
  File "test.py", line 26, in <module>
    doc.generate_pdf(clean_tex=False,compiler='pdflatex')
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.7/site-packages/pylatex/document.py", line 280, in generate_pdf
    'Either specify a LaTex compiler ' +
pylatex.errors.CompilerError: No LaTex compiler was found
You can see some of the things I've tried based on other people's suggestions: 1. if I just open a python console in this directory, and type:
from pylatex import Document, Section, Subsection, Command
from pylatex.utils import italic, NoEscape
import pdflatex
there are no errors, implying importing was successful.
- I saw another recommendation that perl must be installed, which it is: - localhost:test1$ perl --version : returns info about perl 
- I've specified the compiler as was suggested elsewhere on StackOverflow: 'doc.generate_pdf(clean_tex=False,compiler='pdflatex')' 
What else can I do? The ultimate aim is I have generated strings and an image with python, and I want to put them both into a PDF and format, in case there is a better alternative that anyone can suggest. P.s. I'm aware of the tex stack exchange, but I specifically need a way for latex to interact with python, which is why I asked here.
回答1:
Apparantly you'll need to run these two apt-get dependencies
sudo apt-get install latexmk
sudo apt-get install -y texlive-latex-extra
also install pdflatex with pip
pip install pdflatex
then use
doc.generate_pdf(compiler='pdflatex')
来源:https://stackoverflow.com/questions/55601901/pylatex-pylatex-errors-compilererror-no-latex-compiler-was-found