Python 3.7 pdflatex filenotfounderror

920 Views Asked by At

I am using python 3.7 with PyCharm on Windows 10. I have a Tex file and want to generate a pdf with pdflatex.

pdfl = PDFLaTeX.from_texfile('test.tex')
pdf, log, completed_process = pdfl.create_pdf(keep_pdf_file=True, keep_log_file=True)

I keep receiving the following error: FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\myusername\AppData\Local\Temp\tmps48h0jgi\file.pdf' The program tries to find a certain file.pdf in my user folder in a temp folder. (Texlive and TexStudio is also installed and working.)

What am I doing wrong?

Thanks.

1

There are 1 best solutions below

0
On

Just specify where your .tex file is located.

 def tex_pdf():
    current_path = os.path.dirname(os.path.dirname(__file__))
    media_folder = os.path.join(current_path, 'media/')


    with open(f'{media_folder}tex/sometexfile.tex', 'w') as file:
        file.write('\\documentclass{article}\n')
        file.write('\\begin{document}\n')
        file.write('Hello Palo Alto!\n')
        file.write('\\end{document}\n')

    pdfl = PDFLaTeX.from_texfile(f'{media_folder}tex/sometexfile.tex')
    pdf = pdfl.create_pdf(keep_pdf_file=True, keep_log_file=False)