Python 子进程没有这样的文件或目录错误

Python 子进程没有这样的文件或目录错误,python,subprocess,latexmk,Python,Subprocess,Latexmk,作为更大代码的一部分,我尝试使用子进程创建一个调用latexmk编译器的函数,但我始终得到FileNotFoundError:[Errno 2]没有这样的文件或目录:“latexmk”:“latexmk” 但是,如果我直接在终端中编写命令,一切都会正常工作:latexmk--pdf test.tex 如果这很重要,我将使用MacOS Mojave 10.14.6,通过anaconda运行python 3.6 spyder 我已经检查了以下链接: 如果有什么能解决问题,我就错过了 为了让

作为更大代码的一部分,我尝试使用
子进程创建一个调用
latexmk
编译器的函数,但我始终得到
FileNotFoundError:[Errno 2]没有这样的文件或目录:“latexmk”:“latexmk”

但是,如果我直接在终端中编写命令,一切都会正常工作:
latexmk--pdf test.tex

如果这很重要,我将使用MacOS Mojave 10.14.6,通过anaconda运行python 3.6 spyder

我已经检查了以下链接:

如果有什么能解决问题,我就错过了

为了让每个人的生活更轻松,这里有一个指向.tex文件的链接[您可以使用自己的]:

输入latexmk
后将其输出到终端:

latexmk是散列的(/Library/TeX/texbin/latexmk)

下面是一个最小的可重复性示例(不过您的计算机上确实需要latexmk):

我有一种感觉,我严重误解了子流程的工作方式。有什么想法吗

更新:如有必要,完整回溯:

Traceback (most recent call last):

  File "<ipython-input-90-341a2810ccbf>", line 1, in <module>
    pdf('/Users/sergejczan/Desktop/untitled folder/test.tex')

  File "/Users/sergejczan/Desktop/Lab/subprocess error reproduction.py", line 23, in pdf
    output = subprocess.check_output(command)

  File "/anaconda3/lib/python3.6/subprocess.py", line 336, in check_output
    **kwargs).stdout

  File "/anaconda3/lib/python3.6/subprocess.py", line 403, in run
    with Popen(*popenargs, **kwargs) as process:

  File "/anaconda3/lib/python3.6/subprocess.py", line 709, in __init__
    restore_signals, start_new_session)

  File "/anaconda3/lib/python3.6/subprocess.py", line 1344, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)

FileNotFoundError: [Errno 2] No such file or directory: 'latexmk': 'latexmk'


您认为有没有办法让代码自动找到路径?

在shell配置中,
latexmk
是别名还是shell函数,而不是另一个命令?如果没有,您的Python脚本是否以与交互式shell相同的路径运行?类似于@chepner所问的问题:
哪个最新版本的
的输出是什么?不要在注释中添加回溯…只需更新您的问题。这对人们要求的几乎所有信息都适用。你必须把它哑一点,我4个月前开始编码,你怎么知道
latexmk
是否是别名?再次更新问题,用粗体,这有用吗/这回答了问题吗?
Traceback (most recent call last):

  File "<ipython-input-90-341a2810ccbf>", line 1, in <module>
    pdf('/Users/sergejczan/Desktop/untitled folder/test.tex')

  File "/Users/sergejczan/Desktop/Lab/subprocess error reproduction.py", line 23, in pdf
    output = subprocess.check_output(command)

  File "/anaconda3/lib/python3.6/subprocess.py", line 336, in check_output
    **kwargs).stdout

  File "/anaconda3/lib/python3.6/subprocess.py", line 403, in run
    with Popen(*popenargs, **kwargs) as process:

  File "/anaconda3/lib/python3.6/subprocess.py", line 709, in __init__
    restore_signals, start_new_session)

  File "/anaconda3/lib/python3.6/subprocess.py", line 1344, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)

FileNotFoundError: [Errno 2] No such file or directory: 'latexmk': 'latexmk'

output = subprocess.check_output(command,env = {'PATH': '/anaconda3/bin:/Users/sergejczan/anaconda3/bin:/Users/sergejczan/Desktop/Lab/anaconda2/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin'})