TransWikia.com

usepackage{python} not working in miktex (latex), cant run python code in latex document

TeX - LaTeX Asked by minus on March 30, 2021

I want to obtain the results of a python code in a tex document. I have used usepackage{python} but it doesn’t work. Im using windows 10 and visual studio code with the extension latex workshop. I also have installed python.sty in the path C:Program FilesMiKTeXtexlatexpythonpython.sty

documentclass{article}

usepackage{python}

begin{document}

Testing python package in latex document.

begin{python}
print('testing')
2 + 2
a= 3
a**4
end{python}

end{document}

One Answer

There are two possible points of failure here: First, do you have Python installed on your computer? TeX is not magic, python.sty relies on an external Python interpreter rather than parsing and interpreting the Python code itself (which is theoretically possible but implausible and would likely be impractical if it were actually implemented).

Assuming you have Python, your second point of failure is that the default configuration of TeX is to not allow shell escapes. There are two ways to do this: One is to add -shell-escape to the LaTeX command to turn it on. Alternatively, you can make shell escape available to all runs of LaTeX by editing texmf.cnf and adding shell_escape = t to that file. Except since you're using MikTeX, it's a bit different. You'll use the command

initexmf --edit-config-file=pdflatex

(assuming it's pdflatex that you're using) to edit the settings). I can't address this too specifically since I'm a Mac guy, but I'd suggest digging into https://docs.miktex.org for the full story.

Answered by Don Hosek on March 30, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP