0

So, I'm trying to use python to compile some latex. For this very basic pylatex code:

from pylatex import Document, Section, Subsection, Command
from pylatex.utils import NoEscape

# Create a new document
doc = Document()

# Add a section and some content
with doc.create(Section('Introduction')):
   doc.append('Hello, this is a simple LaTeX document generated using Python and pylatex!')

# Generate and save the LaTeX document
doc.generate_tex('example_pylatex')
doc.generate_pdf('example_pylatex', clean_tex=False)

print("LaTeX file 'example_pylatex.tex' and PDF 'example_pylatex.pdf' created successfully.")

it returns:

File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pylatex/document.py", line 325, in generate_pdf
    raise (pylatex.errors.CompilerError: No LaTex compiler was found. Either specify a LaTex compiler or make sure you have latexmk or pdfLaTex installed.

According to suggestions online, i have downloaded basicTeX, and it is currently under Macintosh HD/usr/local/texlive/2024basic/bin/universal-darwin. The exact directory is shown here:

the directory under texlive

In nano ~/.zshrc, I have the line export PATH=/usr/local/texlive/2024basic/bin/universal-darwin:$PATH, and i saved it, after which i used source nano ~/.zshrc to update it.

I also have latexmk installed with tlmgr install latexmk, as well as pdflatex with tlmgr install pdftex. and I used the --version command to verify that they are up to date.

But even after all this, it just returns that same initial error.

New contributor
SupersonicMan12 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
7
  • Welcome! can you compile the example.tex manually with pdflatex example.tex? If so, what does which pdflatex return? If not, what does echo $PATH return?
    – cfr
    Commented Jul 11 at 2:22
  • pdflatex example_pylatex.tex This is pdfTeX, Version 3.141592653-2.6-1.40.26 (TeX Live 2024) (preloaded format=pdflatex) restricted \write18 enabled. entering extended mode ! I can't find file `example_pylatex.tex'. <*> example_pylatex.tex Commented Jul 11 at 2:34
  • echo $PATH returned Library/Frameworks/Python.framework/Versions/3.12/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/Library/Frameworks/Python.framework/Versions/3.12/bin:/Library/Frameworks/Python.framework/Versions/3.11/bin:/Library/Frameworks/Python.framework/Versions/3.11/bin:/Library/Frameworks/Python.framework/Versions/3.12/bin:/Library/Frameworks/Python.framework/Versions/3.12/bin:/Library/Frameworks/Python.framework/Versions/3.12/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/3.9/bin:/opt/anaconda3/con.... [and more] Commented Jul 11 at 2:35
  • When you say you downloaded basicTeX, what did you do exactly? Did you download MacTeX or something else? I'm assuming pdflatex is not in PATH when python is invoked. MacTeX ought to take care of that for you, but if you had to add it yourself, you may have to do a bit more. Did you log out and back in since altering .zschrc? Because sourcing it is only going to change it for that particular shell.
    – cfr
    Commented Jul 11 at 3:21
  • i wanted macTeX but it was too large, so i went for basicTex, i downloaded it from their official website, and it was a .pkg file, i followed the installation steps and it installed basictex in the directory i screenshotted above. Emmm... right now when i use "nano ~/.zshrc", i can still see the line "export PATH=/usr/local/texlive/2024basic/bin/universal-darwin:$PATH", so i think i saved it properly?? Commented Jul 11 at 3:59

0

You must log in to answer this question.

Browse other questions tagged .