0

I wrote two different python scripts (python 3.10.4) and it works on my Windows 10 PC, but not on a second one which I have here for testing, also Windows 10.

The problem is subprocess and I have no clue what the problem could be. Any suggestions? The subprocess should convert some latex files in a pdf.

proc = subprocess.Popen(['pdflatex',newFilename])
proc.communicate()`

Console Feedbacks File1&File2:

proc = subprocess.Popen(['pdflatex', newFilename])
File "subprocess.py", line 966, in __init__
File "subprocess.py", line 1435, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified```
proc = subprocess.Popen(['pdflatex',newFilename])
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line
966, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line
1435, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
martineau
  • 119,623
  • 25
  • 170
  • 301
thomkell
  • 195
  • 1
  • 11
  • 1
    Well the error clearly says it doesn't find the file pdflatex, make sure it exists on the other pc ? – Achille G Apr 12 '22 at 12:12
  • Yes it is exactly the same folder with same files as on the other system which it worked. – thomkell Apr 12 '22 at 12:17
  • Suggestion: See [How do I format my posts using Markdown or HTML?](https://stackoverflow.com/help/formatting) – martineau Apr 12 '22 at 12:20
  • I could solve it, the problem was the installation of python.. my colleague installed it with the appstore and I didn't realize that.. after uninstalling and and installing the version from python.org everything worked out.. it might had been a path problem.. thanks for your help! – thomkell Apr 13 '22 at 08:20

1 Answers1

1

Well it doesn't necessarily have to do with the fact that you use different computers or with a subprocess error. The error code is as follows:

FileNotFoundError: [WinError 2] The system cannot find the file specified

On what program are you running Python on your second computer? You should check whether or not your current working directory, the directory in which your Python code is running, is the same directory in which the file is located. You can do a quick check by looking through your documents or by using:

import os

cwd=os.getcwd()
print(cwd)

This lets you see in which directory your Python file is running, now check where the file is located on the computer.

sidereal
  • 36
  • 6
  • thanks for your answer but I tried that already the path to the files are relative – thomkell Apr 12 '22 at 12:26
  • Call subprocess.Popen with shell=True: ```proc = subprocess.Popen(['pdflatex',newFilename], shell = True)``` let me know if that changes anything. I also see that you haven't used a filepath; take a look at [this](https://stackoverflow.com/questions/1685157/how-can-i-specify-working-directory-for-popen) regarding how to use subprocess.Popen() – sidereal Apr 12 '22 at 12:31
  • With `shell=True` the code just skips the `subprocess` but in addition i get the following message: `'pdflatex' is not recognized as an internal or external command, operable program or batch file` – thomkell Apr 12 '22 at 13:19
  • Well yes that's because of what I explained earlier on. You didn't use a filepath; ```pdflatex``` is not recognized since there's no filepath. Please re-read the links I sent you. Print out the cwd in which the pdflatex file is located in and use that in the ```subprocess.Popen()``` method. – sidereal Apr 12 '22 at 13:20
  • I could solve it, the problem was the installation of python.. my colleague installed it with the appstore and I didn't realize that.. after uninstalling and and installing the version from python.org everything worked out.. it might had been a path problem.. thanks for your help! – thomkell Apr 13 '22 at 08:20
  • No problem! Glad it was solved @thomkell – sidereal Apr 13 '22 at 11:25