How do I check from within python whether LaTeX and TeX Live are installed on a computer? [duplicate]
Asked Answered
D

1

6

I am writing a python program which generates TeX code that gets compiled into a PDF document. For this to work, I need to make sure that the user has some distribution of LaTeX installed on their computer. How do I do this from within Python 2.7 in a platform-independent way?

Derosier answered 30/11, 2016 at 17:42 Comment(0)
I
8

Update for Python 3.11 and 3.12+:

According to PEP 632, distutils has been deprecated, use shutil.which:

if shutil.which('latex'): print('latex installed')

Before Python 3.10:

from distutils.spawn import find_executable
if find_executable('latex'): print('latex installed')

This should do what you want.

Interdepartmental answered 30/11, 2016 at 17:52 Comment(2)
distutils is deprecated...Aldehyde
@DarkoVeberic I have updated the answer with a 3.12+ solution, which duplicates this answer: https://mcmap.net/q/92207/-test-if-executable-exists-in-pythonInterdepartmental

© 2022 - 2024 — McMap. All rights reserved.