Skip to content
Advertisement

‘pdflatex’ not found in subprocess within a bundled PyInstaller APP

I am attempting to create a macOS standalone app from a PyQt5 GUI using PyInstaller. All works apart from automatically generating a PDF from a TEX file using the pdflatex module (in conjunction with Pylatex).

Both the pylatex and pdflatex modules require calling the subprocess module, which is done as following:

fp = subprocess.run(args, input=self.latex, env=env, timeout=15, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

Where args=['pdflatex', '-output-directory=/Users/Desktop', '-interaction-mode=batchmode', '-jobname=test']

This however does not work within the bundled app as it is crashing with the following error which I am logging to a file:

[Errno 2] No such file or directory: 'pdflatex' 

Evidently, the pdflatex executable isn’t being included/ found in the bundle. Running which pdflatex in the terminal outputs the following directory: /Library/TeX/texbin/pdflatex So I have tried to add the path with the following PyInstaller command:

pyinstaller --noconsole --onefile --path "/Library/TeX/texbin" main.py

But the app still cannot find the pdflatex executable at runtime, whereas the terminal executable works without issues. I have exhausted all similar posts online and ran out of things to try so I was hoping someone might guide me to the solution.

Related info:

  • macOS version: 10.13.6 High Sierra
  • Python: 3.8
  • PyInstaller: 5.1

Advertisement

Answer

I had the same problem and I just solved it by editing the runtime environment generated by PyInstaller. In my case the npm command was not found and after running which npm in terminal I could see that npm was located in /usr/local/bin, path that is not included by PyInstaller on macOS.

So my solution is to run this at app startup:

local_bin = '/usr/local/bin'
if local_bin not in os.environ["PATH"]:
   os.environ["PATH"] += os.pathsep + local_bin
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement