Blurie
Blurie

Reputation: 148

Pylatex error when generate PDF file - No such file or directory

I just want to use Pylatex to generate the pdf file. I look at the basic example and re-run the script but it raised the error: OSError: [Errno 2] No such file or directory.

Here is my script:

import sys
from pylatex import Document, Section, Subsection, Command
from pylatex.utils import italic, NoEscape


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__':
    reload(sys)
    sys.setdefaultencoding('utf8')
    # Basic document
    doc = Document()
    fill_document(doc)

    doc.generate_pdf("full")
    doc.generate_tex()

And the error:

Traceback (most recent call last):
  File "/Users/code/Test Generator/Generate.py", line 34, in <module>
    doc.generate_pdf("full")
  File "/Library/Python/2.7/site-packages/pylatex/document.py", line 227, in generate_pdf
    raise(os_error)
OSError: [Errno 2] No such file or directory

Can someone help me ? :-D thanks a lot.

Upvotes: 2

Views: 4341

Answers (2)

Andre Araujo
Andre Araujo

Reputation: 2400

Is the pdflatex command in your PATH when running the python script? And be really sure that you have installed texlive and if it then still doesn't work, try install latexmk as well.

I had the same problem, just set your PATH, considering you have texlive installed.

In my case, he problem was the PATH. I was running an web site using Flask, hosting using uWsgi as service, and PATH was set just whith my virtualenv.

So I fixed adding ":/usr/bin" and worked, see bellow:

[Unit]
Description=uWSGI instance to serve myproject
After=network.target

[Service]
User=www-data
Group=www-data
WorkingDirectory=/sites/simapp
Environment="PATH=/env/flask3/bin:/usr/bin"
ExecStart=/env/flask3/bin/uwsgi --ini /sites/simapp/simapp.ini

[Install]
WantedBy=multi-user.target

Upvotes: 0

drwahl
drwahl

Reputation: 21

Based on the code around the error, you're probably missing a latex compiler:

compilers = (
    ('latexmk', latexmk_args),
    ('pdflatex', [])
)

Try doing this:

apt-get install latexmk

Upvotes: 2

Related Questions