我在 Windows 10 上使用 python 3.7 和 PyCharm。我有一个 Tex 文件,想用 pdflatex 生成 pdf。
pdfl = PDFLaTeX.from_texfile('test.tex')
pdf, log, completed_process = pdfl.create_pdf(keep_pdf_file=True, keep_log_file=True)
我不断收到以下错误:FileNotFoundError:[Errno 2]没有这样的文件或目录:'C:\ Users \ myusername \ AppData \ Local \ Temp mps48h0jgi ile.pdf' 该程序尝试在临时文件夹中的我的用户文件夹中查找某个 file.pdf。 (Texlive 和 TexStudio 也已安装并运行。)
我做错了什么?
谢谢。
只需指定 .tex 文件所在的位置即可。
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)
我也遇到了这个错误,对我来说上述解决方案不起作用。这是一个适合我的解决方案:
pdfl = PDFLaTeX.from_texfile('test.tex')
pdfl.set_interaction_mode() # setting interaction mode to None.
pdf, log, completed_process = pdfl.create_pdf(keep_pdf_file=True, keep_log_file=True)
在 debuggin 时,我发现交互模式是 pdflatex 的一个意外参数。因此,它无法创建 file.pdf 文件,然后也无法找到它。当 Interaction_mode 为 None 时,不会给出参数并且错误已解决。