为什么我的脚本没有创建.tex 文件?

问题描述 投票:0回答:1

我尝试运行此脚本(来自https://tug.org/tug2019/slides/slides-ziegenhagen-python.pdf,第12页)

import subprocess, os

with open("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")


x = subprocess.call("pdflatex sometexfile.tex")
if x != 0:
  print("Exit-code not 0, please check result!")
else:
  os.system("start sometexfile.pdf")

但它给了我以下错误:

line 39, in <module>
    x = subprocess.call("pdflatex sometexfile.tex")
  File "/usr/lib/python3.10/subprocess.py", line 345, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.10/subprocess.py", line 971, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.10/subprocess.py", line 1863, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'pdflatex sometexfile.tex'

预先感谢您的帮助!

python operating-system subprocess latex
1个回答
0
投票

我用 os.system("pdflatex sometexfile.tex") 而不是 subprocess.call("pdflatex sometexfile.tex") 解决了它。

© www.soinside.com 2019 - 2024. All rights reserved.